語言

AlternationConverter.Values 屬性

定義

會得到一個物件清單,當 AlternationConverter 方法傳遞 Convert(Object, Type, Object, CultureInfo) 整數時會回傳這些物件。

public:
 property System::Collections::IList ^ Values { System::Collections::IList ^ get(); };
public System.Collections.IList Values { get; }
member this.Values : System.Collections.IList
Public ReadOnly Property Values As IList

屬性值

當方法傳遞AlternationConverter整數時,會Convert(Object, Type, Object, CultureInfo)回傳的物件清單。

範例

以下範例創造 a ListBox ,並使用兩個 AlternationConverter 物件交替表示 Background 和 FontStyle 的元素。

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

    <AlternationConverter x:Key="FontStyleConverter">
      <FontStyle >Italic</FontStyle>
      <FontStyle >Normal</FontStyle>
    </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="FontStyle" 
              Value="{Binding RelativeSource={RelativeSource Self},
                     Path=(ItemsControl.AlternationIndex),
                     Converter={StaticResource FontStyleConverter}}"/>
    </Style>

  </Grid.Resources>

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

備註

當你使用 將 AlternationConverter 屬性綁定到交替值時,屬性 Values 包含了指派給該屬性的物件。 例如,如果你想讓 a ListBox 中的物品有藍色和淺藍色交替的背景,你就在 中加入藍色SolidColorBrush和淺藍色SolidColorBrushValues。

適用於