简体   繁体   English

WPF:如何在 DataGridCheckBoxColumn 中添加 Checked 和 Unchecked 事件?

[英]WPF : How to add Checked and Unchecked events in the DataGridCheckBoxColumn?

WPF : How to add Checked and Unchecked events in the DataGridCheckBoxColumn? WPF:如何在 DataGridCheckBoxColumn 中添加 Checked 和 Unchecked 事件?

<DataGridCheckBoxColumn Header="Choose" x:Name="choose">
    <DataGridCheckBoxColumn.CellStyle>
        <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}">
            <EventSetter Event="CheckBox.Checked" Handler="OnChecked"/>
            <EventSetter Event="CheckBox.Unchecked" Handler="OnChecked"/
        </Style>
     </DataGridCheckBoxColumn.CellStyle>
</DataGridCheckBoxColumn>

在此处输入图片说明

Your XAML works fine the problem lies withing you getting the Check Box.您的 XAML 工作正常,问题在于您获取复选框。 You should be able to access the element from the Check Box you triggered with the Unchecked or Checked Event.您应该能够从您使用 Unchecked 或 Checked 事件触发的复选框访问该元素。

Example:例子:

var ch = sender as Checkbox;
var row = data_kala.ItemContainerGenerator.ContainerFromItem(ch) as DataGridRow;
bool ischecked = ch.IsChecked;

if (ischecked) {
    row.BackGround = Brushes.Gray;
}
else {
    row.BackGround = Brushes.White;
}

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

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