Datagrid AutoGenerateColumns 按每个数字显示我的列表<List<int>>,而不是总和和计数

Datagrid AutoGenerateColumns to display my List<List<int>> by each number, not a sum and count

或显示它们的方式。

我正在尝试制作数独游戏并希望将我的数据网格作为显示,但它的 AutoGenerateColumns 仅显示数字和计数的总和。有没有办法让我的 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