gpt4 book ai didi

c# - 未触发DataGrid上复选框的未选中事件

转载 作者:太空宇宙 更新时间:2023-11-03 17:04:49 27 4
gpt4 key购买 nike

我已处理事件以检查/未检查数据网格上的复选框

        <DataGridCheckBoxColumn Header="Emp Acknowlegement" Binding="{Binding Path=Trained}" Width="*">
<DataGridCheckBoxColumn.ElementStyle>
<Style TargetType="CheckBox">
<Setter Property="IsEnabled" Value="False"/>
<EventSetter Event="Checked" Handler="empAck_OnCheck"/>
<EventSetter Event="Unchecked" Handler="empAck_OnUncheck"/>
<Style.Triggers>
<DataTrigger Binding="{Binding isUser}" Value="1">
<Setter Property="IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridCheckBoxColumn.ElementStyle>
</DataGridCheckBoxColumn>
<DataGridCheckBoxColumn Header="Effectiveness Check" Binding="{Binding Path=EffectiveCheck}" Width="*">
<DataGridCheckBoxColumn.ElementStyle>
<Style TargetType="CheckBox">
<Setter Property="IsEnabled" Value="False"/>
<EventSetter Event="Checked" Handler="effAck_OnCheck"/>
<EventSetter Event="Unchecked" Handler="effAck_OnUncheck"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Level}" Value="2">
<Setter Property="IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridCheckBoxColumn.ElementStyle>
</DataGridCheckBoxColumn>


该复选框将触发两个事件。第一个仅触发Checked事件。我将处理程序交换为“已检查”和“未检查”,以查看是否是导致问题的未检查方法,但它运行正确。看来该事件没有触发。第二个框的代码相同,但是会按预期触发。

    private void empAck_OnCheck(object sender, RoutedEventArgs e)
{
MessageBox.Show("Checked");

}

public void empAck_OnUncheck(object sender, RoutedEventArgs e)
{
MessageBox.Show("Unchecked");

}

最佳答案

尝试另一种方法

//It's not answer to question but it will work to resolve it

//USE click event for both, add code
<EventSetter Event="Clicked" Handler="empAck_OnClicked"/>

//add event as
public void empAck_OnClicked(object sender, RoutedEventArgs e)
{
CheckBox c=(CheckBox) sender;
if(c.IsChecked==true)
{

}
if(c.IsChecked==false)
{

}
}

关于c# - 未触发DataGrid上复选框的未选中事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58417870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com