<UserControl x:Class="ConditionalCellFormatting.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
	xmlns:gridview="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"
	xmlns:local="clr-namespace:ConditionalCellFormatting"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
	<UserControl.Resources>
		<local:PriceToColorConverter x:Key="MyConverter" />
		
		<SolidColorBrush x:Key="GridLinesFill" Color="#FFB3B3B3"/>
		<SolidColorBrush x:Key="GridViewRowNormalBackground" Color="#FFFFFFFF"/>
		<LinearGradientBrush x:Key="GridViewRowSelectedBackground" EndPoint="0.5,1" StartPoint="0.5,0">
			<GradientStop Color="#FFFFCA5D" Offset="1"/>
			<GradientStop Color="#FFFFDC9C" Offset="0"/>
		</LinearGradientBrush>
		<SolidColorBrush x:Key="GridViewDisabledBackground" Color="#FFEEEEEE"/>
		<SolidColorBrush x:Key="GridViewDisabledBorderBrush" Color="#FFBBBBBB"/>
		<SolidColorBrush x:Key="GridViewDisabledForeground" Color="#FF6F6F6F"/>
		<ControlTemplate x:Key="GridViewCellTemplate" TargetType="gridview:GridViewCell">
			<Grid x:Name="SelectionBackground" Background="{Binding Price, Converter={StaticResource MyConverter}}">
				<VisualStateManager.VisualStateGroups>
					<VisualStateGroup x:Name="CommonStates">
						<VisualState x:Name="Normal"/>
					</VisualStateGroup>
					<VisualStateGroup x:Name="EditingStates">
						<VisualState x:Name="Edited">
							<Storyboard>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_EditorPresenter" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentPresenter" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridViewCellBorder" Storyboard.TargetProperty="Background">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource GridViewRowNormalBackground}"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentBorder" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentBorder" Storyboard.TargetProperty="Stroke">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{StaticResource GridViewRowSelectedBackground}"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentBorder" Storyboard.TargetProperty="StrokeThickness">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="2"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentBorder" Storyboard.TargetProperty="StrokeDashArray">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0"/>
								</ObjectAnimationUsingKeyFrames>
							</Storyboard>
						</VisualState>
						<VisualState x:Name="Display">
							<Storyboard>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentPresenter" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
								</ObjectAnimationUsingKeyFrames>
							</Storyboard>
						</VisualState>
						<VisualState x:Name="Current">
							<Storyboard>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_EditorPresenter" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentPresenter" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="CurrentBorder" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
								</ObjectAnimationUsingKeyFrames>
							</Storyboard>
						</VisualState>
					</VisualStateGroup>
					<VisualStateGroup x:Name="ValueStates">
						<VisualState x:Name="Valid">
							<Storyboard>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="InvalidBorder" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ErrorIcon" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Collapsed"/>
								</ObjectAnimationUsingKeyFrames>
							</Storyboard>
						</VisualState>
						<VisualState x:Name="Invalid">
							<Storyboard>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="InvalidBorder" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ErrorIcon" Storyboard.TargetProperty="Visibility">
									<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="Visible"/>
								</ObjectAnimationUsingKeyFrames>
							</Storyboard>
						</VisualState>
					</VisualStateGroup>
					<VisualStateGroup x:Name="DisabledStates">
						<VisualState x:Name="Enabled"/>
						<VisualState x:Name="Disabled">
							<Storyboard>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="SelectionBackground" Storyboard.TargetProperty="Background">
									<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GridViewDisabledBackground}"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_HorizontalGridLine" Storyboard.TargetProperty="Fill">
									<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GridViewDisabledBorderBrush}"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_VerticalGridLine" Storyboard.TargetProperty="Fill">
									<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GridViewDisabledBorderBrush}"/>
								</ObjectAnimationUsingKeyFrames>
								<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentPresenter" Storyboard.TargetProperty="Foreground">
									<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GridViewDisabledForeground}"/>
								</ObjectAnimationUsingKeyFrames>
							</Storyboard>
						</VisualState>
					</VisualStateGroup>
				</VisualStateManager.VisualStateGroups>
				<Border x:Name="GridViewCellBorder" UseLayoutRounding="True" Background="Transparent" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/>
				<gridview:AlignmentContentPresenter x:Name="PART_ContentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Visible" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" Foreground="{TemplateBinding Foreground}" TextAlignment="{TemplateBinding TextAlignment}" TextDecorations="{TemplateBinding TextDecorations}" TextWrapping="{TemplateBinding TextWrapping}"/>
				<ContentPresenter x:Name="PART_EditorPresenter" HorizontalAlignment="Stretch" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Visibility="Collapsed"/>
				<Rectangle x:Name="PART_HorizontalGridLine" Fill="{StaticResource GridLinesFill}" Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom"/>
				<Rectangle x:Name="PART_VerticalGridLine" Fill="{StaticResource GridLinesFill}" HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="1"/>
				<Rectangle x:Name="CurrentBorder" Stroke="#FF000000" StrokeDashArray="1.5" StrokeDashCap="Round" StrokeDashOffset="0" StrokeThickness="1" Height="Auto" Margin="0" Width="Auto" Visibility="Collapsed"/>
				<Rectangle x:Name="InvalidBorder" Stroke="#FFDB000C" StrokeThickness="2" Height="Auto" Margin="0" Width="Auto" Visibility="Collapsed"/>
				<Grid x:Name="ErrorIcon" Height="18" HorizontalAlignment="Right" Margin="2,0,2,0" VerticalAlignment="Center" Width="18" Visibility="Collapsed">
					<Ellipse Fill="#FF535353"/>
					<Ellipse Fill="#FFCE3527" Stroke="#FFFFFFFF" Margin="1,1,1,1"/>
					<Path Stretch="Fill" Margin="0.999,1,1.001,8.134" Data="M16,8 C8.127,4.9999293 6.627,10.999763 0,8 0,3.581722 3.581722,0 8,0 12.418278,0 16,3.581722 16,8 z">
						<Path.Fill>
							<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
								<GradientStop Color="#99FFFFFF" Offset="0"/>
								<GradientStop Color="#33FFFFFF" Offset="1"/>
							</LinearGradientBrush>
						</Path.Fill>
					</Path>
					<Path Stretch="Fill" Stroke="#FF000000" StrokeThickness="2" Margin="5.168,5.748,4.832,4.252" Data="M0.50001547,0.5 L6.5000797,6.5000169 M6.5000155,0.5 L0.5,6.5000704"/>
					<Path Fill="#FFCE3527" Stretch="Fill" Stroke="#FFFFFFFF" StrokeThickness="2" Margin="5.085,5.084,4.915,4.916" Data="M0.50001547,0.5 L6.5000797,6.5000169 M6.5000155,0.5 L0.5,6.5000704"/>
				</Grid>
			</Grid>
		</ControlTemplate>
		<Style x:Key="GridViewCellStyle" TargetType="gridview:GridViewCell">
			<Setter Property="Template" Value="{StaticResource GridViewCellTemplate}"/>
			<Setter Property="Padding" Value="3,0,3,0"/>
			<Setter Property="BorderBrush" Value="{StaticResource GridViewRowSelectedBackground}"/>
			<Setter Property="VerticalContentAlignment" Value="Center"/>
			<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
			<Setter Property="Background" Value="Transparent"/>
			<Setter Property="UseLayoutRounding" Value="True"/>
		</Style>
	</UserControl.Resources>
  <Grid x:Name="LayoutRoot">
		<telerik:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False" >
			<telerik:RadGridView.Columns>
				<telerik:GridViewDataColumn DataMemberBinding="{Binding ProductName}" Header="Product" />
				<telerik:GridViewDataColumn  CellStyle="{StaticResource GridViewCellStyle}"  DataMemberBinding="{Binding Price}" Header="Price"/>
			</telerik:RadGridView.Columns>
		</telerik:RadGridView>
	</Grid>
</UserControl>
