2015-01-23 1 views
0

내 xaml에 ItemsControl이 있습니다. ItemsControl에 ItemIndex 속성을 사용할 수 있습니까? 항목 지수가 1ItemControl의 항목 색인에 따라 컨트롤 숨기기

<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

인하기위한 작업 같은데 ['MultiValueConverter' (https://msdn.microsoft.com/en-us/library/system.windows.data.imultivalueconverter.aspx). 'Visibility'로 변환하고, 콜렉션과 아이템 자체에 바인딩하고, 첫 번째 인덱스가 있으면 검색하고, 'Visibility.Hidden'을 ... – Sinatr

답변

4

당신은 AlternationIndex에 목록에있는 항목의 수와 트리거 AlternationCount 세트의 조합으로 그것을 할 수 있다면 기본적으로 내가 자식 컨트롤 (TxtNodeData) 중 하나를 숨기려면 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> 
관련 문제