这是在C#中使用Xamarin。我使用跨平台的UI代码。与仅使用.XAML文件类似,但我在代码中执行此操作。
var viewPickerAutoSaveTimer = new StackLayout();
viewPickerAutoSaveTimer.Orientation = StackOrientation.Horizontal;
viewPickerAutoSaveTimer.Padding = 13;
Label labelAutoSaveTimer = new Label()
{
VerticalOptions = LayoutOptions.Center,
Text = "Auto Save Timer"
};
Picker pickerAutoSaveTimer = new Picker()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Center,
SelectedIndex = 1,
Items = { "1", "2", "3" }
};
viewPickerAutoSaveTimer.Children.Add(labelAutoSaveTimer);
viewPickerAutoSaveTimer.Children.Add(pickerAutoSaveTimer);
接下来我有以下代码..
new TableSection ("AUTO SAVE") {
new SwitchCell {
Text = "Enable Auto Save:"
},
new ViewCell
{
View = viewPickerAutoSaveTimer
}
},
自动保存计时器旁边的行应显示选择器上的所选项目......但它不会!
答案 0 :(得分:1)
您的对象初始化顺序不正确,您需要在之前指定选择器项,您可以设置从该项集合中选择的项目:
Picker pickerAutoSaveTimer = new Picker()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Center,
Items = { "1", "2", "3" },
SelectedIndex = 1,
};