Bearbeiten

Freigeben über


AlternationConverter.Values Property

Definition

Gets a list of objects that the AlternationConverter returns when an integer is passed to the Convert(Object, Type, Object, CultureInfo) method.

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

Property Value

A list of objects that the AlternationConverter returns when an integer is passed to the Convert(Object, Type, Object, CultureInfo) method.

Examples

The following example creates a ListBox and uses two AlternationConverter objects to alternate the Background and FontStyle of the items.

<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>

Remarks

When you use the AlternationConverter to bind a property to alternating values, the Values property contains the objects that are assigned to the property. For example, if you want items in a ListBox to have alternating blue and light blue backgrounds, you add a blue SolidColorBrush and a light blue SolidColorBrush to Values.

Applies to