简体   繁体   English

我如何在后面的代码中获取WPF DataGrid的Row CheckBox的Checked事件

[英]how can I get the WPF DataGrid's Row CheckBox's Checked Event in code behind

I am having following WPf DataGrid 我正在关注WPf DataGrid

<UserControl x:Class="abc.WPFApp.UCGrid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WPFtoolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
    xmlns:local="clr-namespace:abc.WPFApp">

    <UserControl.Resources>
<!--Restrict editing based on IsVariable-->
        <Style x:Key="CheckBoxCellStyle" TargetType="{x:Type CheckBox}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=IsVariable}" Value="true">
                    <Setter Property="IsEnabled" Value="false"/>
                </DataTrigger>
            </Style.Triggers>
            <Setter Property="HorizontalAlignment" Value="Center"/>
        </Style>
</UserControl.Resources>
<Grid>
        <WPFtoolkit:DataGrid x:Name="UCdataGridView" ItemsSource="{Binding}"
                                                     CellStyle="{StaticResource defaultCellStyle}"
                                                     RowStyle="{StaticResource defaultRowStyle}"
                                                     ColumnHeaderStyle="{StaticResource defaultDataGridColumnHeader}"
                                                     SelectionUnit="FullRow"
                                                     IsSynchronizedWithCurrentItem="True" 
                                                     RowBackground="White" 
                                                     AlternatingRowBackground="AliceBlue"
                                     AutoGenerateColumns="False" SelectionMode="Extended" RowHeaderWidth="20"
                                     CanUserAddRows="True" CanUserDeleteRows="True" CanUserReorderColumns="False" 
                                     CanUserResizeColumns="True" AllowDrop="True" KeyUp="UCGridKeyUp" >
            <WPFtoolkit:DataGrid.Columns>


<WPFtoolkit:DataGridCheckBoxColumn x:Name="dgChkRepeatingData" Binding="{Binding Path=MasterDataFlag}" MaxWidth="135" MinWidth="80"
                                     Header="Repeating data" Visibility="Collapsed" IsReadOnly="{Binding (IsVariable)}" 
                                     EditingElementStyle="{StaticResource CheckBoxCellStyle}"
                                      >
                </WPFtoolkit:DataGridCheckBoxColumn>

                <WPFtoolkit:DataGridCheckBoxColumn MaxWidth="100" Header="Max Element" x:Name="dgChkMaxElement"
                                                   Binding="{Binding Path=MaxElement}" MinWidth="70" Visibility="Collapsed" 
                                    EditingElementStyle="{StaticResource CheckBoxCellStyle}">
                </WPFtoolkit:DataGridCheckBoxColumn>

                <WPFtoolkit:DataGridCheckBoxColumn MaxWidth="100" Header="In For Loop" x:Name="dgChkInForLoop"
                                                   Binding="{Binding Path=InForLoop}" MinWidth="70" Visibility="Collapsed" 
                                    EditingElementStyle="{StaticResource CheckBoxCellStyle}">
                </WPFtoolkit:DataGridCheckBoxColumn>

                <WPFtoolkit:DataGridTextColumn x:Name="dgXPath" Binding="{Binding Path=XPath}" Header="XPath" Width="500"
                                               Visibility="Collapsed" IsReadOnly="{Binding Path=IsVariable}"
                                               EditingElementStyle="{StaticResource TextBoxCellStyle}"/>
</WPFtoolkit:DataGrid.Columns>
        </WPFtoolkit:DataGrid>

Now how can i get the checked event of various columns in code behind file. 现在如何获取文件后面代码中各列的已检查事件。

You can handle SourceUpdated event of the binding on DataGridCheckBoxColumn. 您可以在DataGridCheckBoxColumn上处理绑定的SourceUpdated事件。 To get this event you need to also set 要获得此事件,您还需要设置

NotifyOnSourceUpdated = true

on that binding 在那个约束上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM