在我的xaml中,我有一个ItemsControl。是否可以在ItemsControl上拥有ItemIndex属性?基本上我想隐藏一个子控件(TxtNodeData),如果Item索引是1
<ItemsControl ItemsSource="{Binding ConditionList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="{Binding NodeData}" Name="TxtNodeData"/>
<Button Content="+" />
<ComboBox ItemsSource="{Binding NodeNames}" DisplayMemberPath="name" SelectedValue="{Binding ConditionalNodeId, Mode=TwoWay}" SelectedValuePath="id"> </ComboBox>
<Button Content="-" />
</WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
答案 0 :(得分:4)
您可以将AlternationCount
组合设置为列表中的项目数并将AlternationIndex
触发为1
<ItemsControl ItemsSource="{Binding ConditionList}" AlternationCount="{Binding ConditionList.Count}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="{Binding NodeData}" Name="TxtNodeData">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger
Binding="{Binding
RelativeSource={RelativeSource AncestorType={x:Type ContentPresenter}},
Path=(ItemsControl.AlternationIndex)}"
Value="1">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<!-- other controls -->
</WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>