这是在 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
}
},
Auto Save Timer 旁边的行应该在选择器上显示所选项目......但它没有!
最佳答案
您的对象初始化顺序不正确,您需要分配选择器项目之前您可以设置从项目集合中选择的项目:
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/