C# 根据ItemsControl的项索引隐藏控件

C# 根据ItemsControl的项索引隐藏控件,c#,wpf,xaml,C#,Wpf,Xaml,在我的xaml中,我有一个ItemsControl。是否可以在ItemsControl上具有ItemIndex属性?基本上,如果项目索引为1,我想隐藏一个子控件(TxtNodeData) <ItemsControl ItemsSource="{Binding ConditionList}"> <ItemsControl.ItemTemplate> <DataTemplate> <WrapPanel> &l

在我的xaml中,我有一个ItemsControl。是否可以在ItemsControl上具有ItemIndex属性?基本上,如果项目索引为1,我想隐藏一个子控件(TxtNodeData)

<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>


您可以将
AlternationCount
组合设置为列表中的项数,并在
alternationdex
上触发为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>

您可以将
AlternationCount
组合设置为列表中的项数,并在
alternationdex
上触发为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>

听起来像是一份工作。转换为
可见性
,绑定到集合和项目本身,如果先搜索索引,然后搜索
可见性。隐藏的
…听起来像是一项工作。转换为
可见性
,绑定到集合和项目本身,如果首先搜索索引,则搜索
可见性。隐藏
。。。