wpf - WPF 隐藏 ItemsControl 的第一项(组合框、文本框等)
问题描述
有没有办法仅在纯视图中隐藏 xaml 中的 itemscontrol 中的第一项(组合框)控件?
<ItemsControl ItemsSource="{Binding QueueConditionCollection.Collection,
NotifyOnSourceUpdated=True}"
AlternationCount="2">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ComboBox Name="cmbLogicalOperator"
ItemsSource="{BindingLogicalOperatorCollection.Collection}"
SelectedItem="{Binding LogicalOperatorCollection.Selected,UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
<ItemsControl.ItemTemplate>
</ItemsControl>
实际场景:如果集合只有 1 项,则隐藏控件: 请参见此图。
解决方案
您可以声明一个布尔属性,如果 Collection.Count() == 1 将返回 false,并为您的组合框使用布尔到可见性转换器