UWP 中的数据网格复选框

Datagrid Checkbox in UWP

我正在努力寻找一个在 UWP 中为我的数据网格使用复选框的工作示例。我想使用我的复选框 -> 按一个按钮 -> 执行 X。

我想你们中的任何人都不能给我一个过程的例子或者给我指出一个记录在案的例子吗?谢谢

这是我的:

<StackPanel Margin="169,33,0,0" Height="25" VerticalAlignment="Top" Background="#FF383838"/>
        <controls:DataGrid x:Name="EmployeeGrid" Margin="170,55,35,35"
                  ItemsSource="{x:Bind persons}"
                  CanUserSortColumns="True"
                  AutoGenerateColumns="False" Background="Black"
                           SelectedItem="itemSelected" >
            <controls:DataGrid.Columns>
                <controls:DataGridTextColumn Header="Employee ID"
                                             Binding="{Binding PersonId}"/>
                <controls:DataGridTextColumn Header="First Name"
                                             Binding="{Binding FirstName}"/>
                <controls:DataGridTextColumn Header="Last Name"
                                             Binding="{Binding LastName}"/>
                <controls:DataGridTextColumn Header="Address"
                                             Binding="{Binding Address}"/>
                <controls:DataGridTextColumn Header="Position"
                                             Binding="{Binding Position}"/>
                <controls:DataGridTextColumn Header="Pay Rate (ph)"
                                             Binding="{Binding PayratePH}"/>
                <controls:DataGridTextColumn Header="Sex"
                                             Binding="{Binding Sex}"/>
                <controls:DataGridTextColumn Header="TaxCode"
                                             Binding="{Binding TaxCode}"/>
                <controls:DataGridTextColumn Header="Email"
                                             Binding="{Binding Email}"/>
                <controls:DataGridTextColumn Header="Emergency Contact"
                                             Binding="{Binding EmergencyDetails}"/>
                <controls:DataGridCheckBoxColumn Header="Selected"  
                                                    />
                

            </controls:DataGrid.Columns>
        </controls:DataGrid>

like to use my check box -> press a button -> do X.

DataGrid 包含用于自定义单元格的 DataGridTemplateColumn,您可以将 CheckBox 插入 CellTemplate 并在需要时将 Checked 与数据模型 bool 属性 绑定检查CheckBox,请修改模型的bool 属性.

<controls:DataGridTemplateColumn Header="Check">
    <controls:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <CheckBox Content="{Binding Id}" IsChecked="{Binding IsCheck}" />
            </StackPanel>
        </DataTemplate>
    </controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>

更多详情请参考此代码sample