ItemsControl.AlternationIndex 연결된 속성

정의

교대로 반복되는 항목 컨테이너가 사용되는 경우 항목 컨테이너의 할당된 값을 가져옵니다.

see GetAlternationIndex, and SetAlternationIndex
see GetAlternationIndex
see GetAlternationIndex, and SetAlternationIndex
see GetAlternationIndex
see GetAlternationIndex, and SetAlternationIndex
see GetAlternationIndex

예제

다음 예제에서는 (상속ItemsControl되는) 항목 컨테이너(형식ListBoxItem)가 번갈아 가며 각 컨테이너에 대해 다른 배경과 전경을 지정하는 것을 지정 ListBox 합니다. 이 예제에서는 및 속성을 ItemsControl.AlternationIndex 바인딩 Foreground Background 하고 각 속성에 대해 제공합니다AlternationConverter.

<Grid>
  <Grid.Resources>
    <AlternationConverter x:Key="BackgroundConverter">
      <SolidColorBrush>Blue</SolidColorBrush>
      <SolidColorBrush>CornflowerBlue</SolidColorBrush>
      <SolidColorBrush>LightBlue</SolidColorBrush>
    </AlternationConverter>

    <AlternationConverter x:Key="AlternateForegroundConverter">
      <SolidColorBrush>White</SolidColorBrush>
      <SolidColorBrush>Black</SolidColorBrush>
      <SolidColorBrush>Navy</SolidColorBrush>
    </AlternationConverter>

    <Style x:Key="alternatingWithBinding" TargetType="{x:Type ListBoxItem}">
      <Setter Property="Background" 
              Value="{Binding RelativeSource={RelativeSource Self},
                     Path=(ItemsControl.AlternationIndex),
                     Converter={StaticResource BackgroundConverter}}"/>

      <Setter Property="Foreground" 
              Value="{Binding RelativeSource={RelativeSource Self},
                     Path=(ItemsControl.AlternationIndex),
                     Converter={StaticResource AlternateForegroundConverter}}"/>
    </Style>

  </Grid.Resources>

  <ListBox AlternationCount="3" ItemsSource="{StaticResource data}"
           ItemContainerStyle="{StaticResource alternatingWithBinding}"/>
</Grid>

다음 예제에서는 개체를 사용하여 Trigger 이전 예제와 동일하게 수행합니다.

<Grid>
  <Grid.Resources>
    <Style x:Key="alternatingWithTriggers" TargetType="{x:Type ListBoxItem}">
      <Setter Property="Background" Value="Blue"/>
      <Setter Property="Foreground" Value="White"/>
      <Style.Triggers>
        <Trigger Property="ListBox.AlternationIndex" Value="1">
          <Setter Property="Background" Value="CornflowerBlue"/>
          <Setter Property="Foreground" Value="Black"/>
        </Trigger>
        <Trigger Property="ListBox.AlternationIndex" Value="2">
          <Setter Property="Background" Value="LightBlue"/>
          <Setter Property="Foreground" Value="Navy"/>
        </Trigger>
      </Style.Triggers>
    </Style>

  </Grid.Resources>
  <ListBox AlternationCount="3" ItemsSource="{StaticResource data}" 
           ItemContainerStyle="{StaticResource alternatingWithTriggers}">
  </ListBox>
</Grid>

설명

합니다 AlternationCountItemsControl.AlternationIndex 속성을 사용 하면 두 개 이상의 교대로 반복 되는 항목 컨테이너에 대 한 모양을 지정할 수 있습니다. 예를 들어, 모든 세 번째 항목에 대해 교대로 반복 되는 배경 색을 지정할 수 있습니다는 ItemsControl합니다. ItemsControl.AlternationIndex 각 항목 컨테이너에 할당 되는 ItemsControl합니다. ItemsControl.AlternationIndex 0에서 시작 될 때까지 증가, AlternationCount 1이 고, 한 다음 다시 0에서 뺀 값입니다. 예를 들어, 경우 AlternationCount 이 3이 고에 7 개의 항목이 있는 ItemsControl, 다음 표에서 ItemsControl.AlternationIndex 각 항목에 대 한 합니다.

항목의 위치는 ItemsControl ItemsControl.AlternationIndex
1 0
2 1
3 2
4 0
5 1
6 2
7 0

교대로 반복 되는 항목 컨테이너에 대해 다른 모양을 지정 하 여 여러 가지가 있습니다. 한 가지 방법은 항목 컨테이너의 속성에 바인딩하는 ItemsControl.AlternationIndex합니다. 사용할 수 있습니다는 AlternationConverter 특정 된 항목 컨테이너에 적용 되어야 하는 값을 지정 하려면 ItemsControl.AlternationIndex 값입니다. 값에 따라 항목 컨테이너의 속성의 값을 변경 하려면 트리거를 사용할 수도 있습니다는 ItemsControl.AlternationIndex합니다.

적용 대상