GroupStyle.AlternationCount 속성

정의

교대로 반복되는 GroupItem 개체의 수를 가져오거나 설정합니다.

public:
 property int AlternationCount { int get(); void set(int value); };
public int AlternationCount { get; set; }
member this.AlternationCount : int with get, set
Public Property AlternationCount As Integer

속성 값

Int32

교대로 반복되는 GroupItem 개체 수입니다.

예제

다음 예제에서는 ListBox 바인딩되는 CollectionViewSource 컬렉션의 항목을 그룹화 하 합니다. 이 예제에서는 각 헤더에 대 한 배경색을 교대로 반복 GroupItem 다음을 수행 하 여 두 색상 간:

예제에서는 또한에 있는 항목의 배경색을 교대로 반복를 ListBox 설정 하 여 세 가지 색 간의 AlternationCountListBox 및 바인딩을 BackgroundListBoxItemsControl.AlternationIndex합니다. 이 경우 백그라운드 사이 번갈아 전환 세 가지 색입니다.

CollectionViewSource 그룹 항목은 표시 되지 않도록 합니다. 항목을 그룹화 하는 방법에 대 한 자세한 내용은 방법: 정렬 및 그룹 데이터를 XAML에서 뷰를 사용 하 여입니다.

<StackPanel>

  <StackPanel.Resources>

    <!--Returns a Brush for the header of a GroupItem.-->
    <AlternationConverter x:Key="GroupHeaderBackgroundConverter">
      <SolidColorBrush>LightBlue</SolidColorBrush>
      <SolidColorBrush>LightSteelBlue</SolidColorBrush>
    </AlternationConverter>

    <!--Returns a Brush for a ListBoxItem.-->
    <AlternationConverter x:Key="BackgroundConverter">
      <SolidColorBrush>Silver</SolidColorBrush>
      <SolidColorBrush>LightGray</SolidColorBrush>
      <SolidColorBrush>GhostWhite</SolidColorBrush>
    </AlternationConverter>

  </StackPanel.Resources>

  <ListBox ItemsSource="{Binding Source={StaticResource groupedData}}"
           DisplayMemberPath="CityName" AlternationCount="3" Name="lb">

    <ListBox.GroupStyle>
      <!--Set alternating backgrounds on the header of each group.-->
      <GroupStyle AlternationCount="2">
        <GroupStyle.HeaderTemplate>
          <DataTemplate>
            <TextBlock FontWeight="Bold" 
                       Text="{Binding Path=Name}" 
                       Background="{Binding 
                           RelativeSource={RelativeSource FindAncestor, 
                           AncestorType={x:Type GroupItem}},
                           Path=(ItemsControl.AlternationIndex),
                           Converter={StaticResource 
                                      GroupHeaderBackgroundConverter}}"/>
          </DataTemplate>
        </GroupStyle.HeaderTemplate>
      </GroupStyle>
    </ListBox.GroupStyle>

    <ListBox.ItemContainerStyle>
      <!--Set alternating backgrounds on the items in the ListBox.-->
      <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="Background" 
                Value="{Binding RelativeSource={RelativeSource Self},
                     Path=(ItemsControl.AlternationIndex),
                     Converter={StaticResource BackgroundConverter}}"/>
      </Style>
    </ListBox.ItemContainerStyle>
  </ListBox>
</StackPanel>

설명

합니다 AlternationCount 속성 및 ItemsControl.AlternationIndex 연결 된 속성을 사용 하면 두 개 이상의 교대로 반복 되는 모양을 지정할 수 있도록 GroupItem 개체입니다. 예를 들어, 모든 세 번째 교대로 반복 되는 배경 색을 지정할 수 있습니다 GroupItemItemsControl합니다. ItemsControl.AlternationIndex 각각에 할당 됩니다 GroupItemItemsControl합니다. ItemsControl.AlternationIndex 0에서 시작 될 때까지 증가, AlternationCount 1이 고, 한 다음 다시 0에서 뺀 값입니다. 예를 들어 경우 AlternationCount 이 3이 고 일곱 개의 GroupItem 개체를 ItemsControl, 다음 표에서 ItemsControl.AlternationIndex 각 항목에 대 한 합니다.

위치 GroupItemItemsControl ItemsControl.AlternationIndex
1 0
2 1
3 2
4 0
5 1
6 2
7 0

여러 가지 방법을 사용할 수 있는 대체에 대 한 서로 다른 모양을 지정할 GroupItem 개체입니다. 속성에 바인딩하는 한 가지 방법은 합니다 HeaderTemplate 또는 ContainerStyleGroupStyleItemsControl.AlternationIndex합니다. 사용할 수 있습니다는 AlternationConverter 에 적용 해야 하는 값을 지정 하는 GroupItem 있는 특정 ItemsControl.AlternationIndex 값입니다. 값에 따라 속성의 값을 변경 하려면 트리거를 사용할 수도 있습니다는 ItemsControl.AlternationIndex합니다.

적용 대상