XAML项控件可见性
我的XAML代码中有一个ItemsControl。当一些触发器发生时,我想折叠完整的itemsControl,所以所有的元素XAML项控件可见性,xaml,Xaml,我的XAML代码中有一个ItemsControl。当一些触发器发生时,我想折叠完整的itemsControl,所以所有的元素 <ItemsControl Name="VideoViewControl" ItemsSource="{Binding Videos}"> <ItemsControl.ItemsPanel>
<ItemsControl Name="VideoViewControl" ItemsSource="{Binding Videos}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel ItemHeight="120" ItemWidth="160" Name="wrapPanel1"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<views:VideoInMenuView />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
触发因素:
<DataTrigger Value="videos" Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.VideosEnable}">
<Setter Property="ScrollViewer.Visibility" Value="Visible" TargetName="test1" />
<Setter Property="ScrollViewer.Visibility" Value="Collapsed" TargetName="test2" />
<Setter Property="WrapPanel.Visibility" Value="Collapsed" TargetName="wrapPanel1" />
</DataTrigger>
当我添加最后一个setter时,程序崩溃。
如果没有最后一个setter,它可以正常工作,但不会改变可见性
这个代码有什么问题?使用触发器折叠ItemsControl的所有元素的写入方法是什么?如果要隐藏整个ItemsControl,只需隐藏ItemsControl本身,而不是其内部组件(ScrollViewer和WrapPanel):
这将简单地将ItemsControl本身的可见性设置为Collapsed,听起来就像您想要的那样。我找到了一个解决方案:
我将其添加到itemscontrol的项中:
Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type ItemsControl}}, Path=Visibility, Mode=TwoWay}"
在WPF hittest算法中,我检查了可见性属性是否已折叠
这不是一个好的解决方案,但对我来说很有效
非常奇怪的是,如果将itemscontrol的visibility属性设置为collapsed,则项目的visibility属性是可见的。。。臭虫
同样奇怪的是:hittest可以找到折叠的对象…我已经做了,元素不再可见了,但是我仍然可以通过我使用的WPF hittest找到它们。。当我将Itemscontrol的属性hittestVisible设置为false时,这也是一个问题Itemscontrol的元素仍然可以通过hittest找到所以当我调试hittest时,我得到ItemControl的对象,当我查看属性时,它的可见性是可见的。因此,当您将ItemsControl的属性可见性设置为“折叠”时,仅更改ItemsControl的可见性,而不更改ItemsControl中项目的可见性。因此,我现在需要了解如何将所有itemscontrol元素的可见性设置为colapsed,例如,将itemscontrol的可见性设置为colapsed
Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type ItemsControl}}, Path=Visibility, Mode=TwoWay}"