Datagrid AutoGenerateColumns 按每个数字显示我的 List>,而不是总和
本文关键字:List AutoGenerateColumns int 数字显示 我的 Datagrid | 更新日期: 2023-09-27 18:31:24
或显示它们的方法。
我正在尝试制作一个数独,并希望将我的数据网格作为显示器,但它的自动生成列仅显示数字和计数的总和。有没有办法让我的List<List<int>>
以正常的数独方式显示?
<DataGrid x:Name="siatkaGD"
HorizontalAlignment="Left" Height="372" Margin="10,10,0,0"
VerticalAlignment="Top" Width="480" HeadersVisibility="None"
AutoGenerateColumns="true"/>
siatkaGD.ItemsSource = myListOfInts;
A.) 使用带有文本框的网格,以便您拥有完全控制权。这类似于一个很好的老式 Windows 窗体方法 ->自己控制所有文本框...
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20*" />
<RowDefinition Height="20*" />
<RowDefinition Height="20*" />
<RowDefinition Height="20*" />
<RowDefinition Height="20*" />
<RowDefinition Height="20*" />
<RowDefinition Height="20*" />
<RowDefinition Height="20*" />
<RowDefinition Height="20*" />
</Grid.RowDefinitions>
<TextBox Grid.Column="0"
Grid.Row="0" />
<!--TODO add all your Textboxes...-->
</Grid>
B.)还可以使用任何其他 ItemsControl 来表示值的平面列表。我建议用"CellViewModels"做一个扁平列表......
C.)如果您真的想使用 Datagrid 作为您的选择视图,我建议您使用 MVVM 模式并绑定到"rows-viewModels"列表
D.)阅读本系列文章 https://channel9.msdn.com/coding4fun/articles/Building-a-WPF-Sudoku-Game-Part-1-Introduction-to-WPF-and-XAML