从WPF DataGrid模板列中删除事件处理程序 [英] Remove event handler from WPF DataGrid Template Column

查看:195
本文介绍了从WPF DataGrid模板列中删除事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从数据网格中的模板列中删除事件处理程序



我的XAML:



How can i remove the event handler from a template column in a datagrid

My XAML:

<DataGrid x:Name="dg" AutoGenerateColumns="False" Margin="10,0,0,0">
                <DataGrid.Columns>
<DataGridTemplateColumn Header="Arrived">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox x:Name="Arrived_chk" IsChecked="{Binding Path=Arrive}" Checked="Arrived_chk_Checked" Unchecked="Arrived_chk_Unchecked" />
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                </DataGrid.Columns>
            </DataGrid>







我试过像这样访问控件:



Dim chkbox作为CheckBox = GetTemplateChild(Arrived_chk)



但这会返回null。



我需要访问控件以在某个子进行时删除事件处理程序。



谢谢





更新:



仍在努力解决这个问题我尝试过使用它:



dg.RemoveHandler(CheckBox.Checked,AddressOf Arrived_chk_Checked)



但仍然没有运气。




I have tried getting access to the control like so:

Dim chkbox As CheckBox = GetTemplateChild("Arrived_chk")

but this returns a null.

I need access to the control to remove the event handler while a certain sub takes place.

Thanks


UPDATE:

Still struggling with this I have tried using this:

dg.RemoveHandler(CheckBox.Checked, AddressOf Arrived_chk_Checked)

but still having no luck.

推荐答案

使用click事件而不是check和uncheck解决事件。 CLick事件仅在用户实际按下复选框时触发,而不是在加载数据时触发。
Solved by using the click event instead of check and uncheck event. CLick event only fires if the user actually presses the checkbox instead of firing when the data is loaded.


这篇关于从WPF DataGrid模板列中删除事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆