Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF列表视图和控件_C#_Wpf - Fatal编程技术网

C# WPF列表视图和控件

C# WPF列表视图和控件,c#,wpf,C#,Wpf,我有一个使用VisualTreeHelper的程序,但它只适用于可见的对象。当我使用LogicalTreeHelper时,LTH返回一个空值作为父级。如何修复它 while (parent.GetType() != typeof(ListViewItem)) { if (parent is Selector) break; parent = LogicalTreeHelper.GetParent(p

我有一个使用VisualTreeHelper的程序,但它只适用于可见的对象。当我使用LogicalTreeHelper时,LTH返回一个空值作为父级。如何修复它

while (parent.GetType() != typeof(ListViewItem))
        {
            if (parent is Selector)
                break;

            parent = LogicalTreeHelper.GetParent(parent);
        }
我有一个在一列中带有复选框的列表视图,并且必须在另一列中按名称选择CB,因为CB有一个共享事件。我必须转到父项(ListViewItem),然后在Col2中查找名称,其中是带有图像和文本块的StackPanel。是否有可能将col2中的名称写入例如CB标记作为帮助值。但是我不想要它

enter code here
<ListView>
...
<GridViewColumn Header=" ID" HeaderContainerStyle="{DynamicResource lvcLeft}" >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox x:Name="cbID" IsChecked="{Binding ID}" **Checked="cbID_Checked"** />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header=" Name" Width="200"     HeaderContainerStyle="{DynamicResource lvcLeft}"  >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="{Binding Icon}" />
                                    <TextBlock Text="{Binding Name}"/>
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
...
在此处输入代码
...
...

新增项目:

添加(新的myItem{ID=false,Name=“abc”})

VisualTreeHelper-返回值/对象, LogicalTreeHelper=返回null

但是,在运行时创建/加载ListView项时,是否有其他方法可以识别CB?如果要更改IsChecked(部分或全部)的值,如何接近复选框。如何在ListView中隐藏任何列


非常感谢

选中或取消选中复选框将在相应的
myItem
实例上调用
ID
属性设置器,因为您绑定到该属性。该实例知道自己的
名称
,因此您应该能够在那里执行任何需要执行的操作。为什么需要使用
Checked
事件?选中或取消选中复选框将调用相应
myItem
实例上的
ID
属性设置器,因为您绑定到该属性。该实例知道自己的
名称
,因此您应该能够在那里执行任何需要执行的操作。为什么需要使用
Checked
事件?