我想实现一个GridView在UWP每个项目包含一个TextBlock,Checkbox两个ComboBox。我现在得到的是的Classname instad GridViewItem。我认为这可以通过解决DataTemplate吗?Xaml文件:<Page.Resources> <DataTemplate x:Name="CameraSettingsGridViewTemplate" x:DataType="local:CameraSetting"> <GridViewItem> <StackPanel> <TextBlock Text="{x:Bind Property}"/> <CheckBox/> <ComboBox ItemsSource="{x:Bind Value1}"/> <ComboBox ItemsSource="{x:Bind Value2}"/> </StackPanel> </GridViewItem> </DataTemplate></Page.Resources><Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <GridView Name="CameraSettings" HorizontalAlignment="Left" VerticalAlignment="Top" ItemsSource="{x:Bind CameraSettingsList}"></GridView></Grid>这DataTemplate是解决问题的尝试。CS档案: public sealed partial class CameraSettingsPage : Page { private ObservableCollection<CameraSetting> cameraSettingsList = new ObservableCollection<CameraSetting>(); public ObservableCollection<CameraSetting> CameraSettingsList { get { return this.cameraSettingsList; } } public CameraSettingsPage() { this.InitializeComponent(); this.cameraSettingsList = new ObservableCollection<CameraSetting>() { new CameraSetting() { Property = "prop1", Auto = new CheckBox(), Value1 = new ComboBox() { ItemsSource = new ObservableCollection<string>() { "1", "2" } }, Value2 = new ComboBox() { ItemsSource = new ObservableCollection<string>() { "a", "b" } } } }; } private void Page_Loaded(object sender, RoutedEventArgs e) { }}public class CameraSetting { public string Property { get; set; } public CheckBox Auto { get; set; } public ComboBox Value1 { get; set; } public ComboBox Value2 { get; set; }}在构造我创建一个示例GridViewItem内ObservableCollection,并以此为ItemSource对GridView。
1 回答
- 1 回答
- 0 关注
- 145 浏览
添加回答
举报
0/150
提交
取消