[英]Get containing row from a CheckBox inside of a DataGrid
I have a DataGrid that has auto generated columns. 我有一个具有自动生成的列的DataGrid。 In side of the AutoColumnsGenerated event I am adding an additional column.
在AutoColumnsGenerated事件的旁边,我添加了另一列。 This column is a DataGridTemplateColumn which includes a DataTemplate with it's VisualTree set to a CheckBox.
该列是一个DataGridTemplateColumn,其中包括一个DataTemplate,其VisualTree设置为CheckBox。 I am adding a handler to the CheckBox.ClickEvent in which I will chain a value in the associated row.
我在CheckBox.ClickEvent中添加了一个处理程序,在该处理程序中,我将在关联的行中链接一个值。
If I have multiple DataGrids that are built this way I don't know how to figure out which listview the click event originated from. 如果我有多个以此方式构建的DataGrid,则我不知道如何确定click事件源自哪个listview。
From the click event handler I have access to the check box, but its parent is not set. 从单击事件处理程序中,我可以访问该复选框,但是未设置其父级。 I have also tried using the visual tee helper, but cannot get into the tree in the correct spot.
我也尝试过使用可视T恤助手,但是无法在正确的位置进入树中。
Does anybody know how I can find out the corresponding DataGrid that contains the clicked CheckBox? 有人知道我如何找到包含单击的CheckBox的对应DataGrid吗?
VisualTreeHelper should work. VisualTreeHelper应该可以工作。 Try the following code on the event handler:
在事件处理程序上尝试以下代码:
FrameworkElement fe = sender as FrameworkElement;
while ((fe.GetType() != typeof(DataGrid)) &&
(fe != null))
{
fe = VisualTreeHelper.GetParent(fe) as FrameworkElement;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.