AlternationConverter Class
Converts an integer to and from an object by applying the integer as an index to a list of objects.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
The AlternationConverter type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | AlternationConverter | Initializes a new instance of the AlternationConverter class. |
| Name | Description | |
|---|---|---|
![]() | Convert | Converts an integer to an object in the Values list. |
![]() | ConvertBack | Converts an object in the Values list to an integer. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
You can use the AlternationConverter to bind a property to alternating values. For example, if you want items in a ListBox to have alternating blue and light blue backgrounds, you do the following:
Create an AlternationConverter and add a blue SolidColorBrush and a light blue SolidColorBrush to its Values property.
In a Style for ListBoxItem, bind the Background property to ItemsControl::AlternationIndex and assign the converter you created to the Binding::Converter property.
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>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
