AlternationConverter.Values Egenskap

Definition

Hämtar en lista över objekt som AlternationConverter returneras när ett heltal skickas Convert(Object, Type, Object, CultureInfo) till metoden.

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

Egenskapsvärde

En lista över objekt som AlternationConverter returneras när ett heltal skickas Convert(Object, Type, Object, CultureInfo) till metoden.

Exempel

I följande exempel skapas en ListBox och används två AlternationConverter objekt för att växla objekten Background och 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>

Kommentarer

När du använder AlternationConverter för att binda en egenskap till alternerande värden Values innehåller egenskapen de objekt som har tilldelats egenskapen. Om du till exempel vill att objekt i en ListBox ska ha alternerande blå och ljusblå bakgrunder lägger du till en blå SolidColorBrush och en ljusblå SolidColorBrush i Values.

Gäller för