这是Xamarin的C#语言。我正在使用跨平台的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
}
},
这是结果的屏幕截图-
“自动保存计时器”旁边的行应在选择器上显示所选的项目...但是不会!
最佳答案
您的对象初始化顺序不正确,您需要分配选择器项目,然后才能设置从该项目的集合中选择的项目:
Picker pickerAutoSaveTimer = new Picker()
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.Center,
Items = { "1", "2", "3" },
SelectedIndex = 1,
};
关于c# - 将Label和PickerView放在TableView的同一行上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50126254/