<Page x:Class="FlexGrid101.ConditionalFormatting"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml"       
      xmlns:local="clr-namespace:FlexGrid101"
      mc:Ignorable="d" 
      d:DesignHeight="450" d:DesignWidth="800"
      Title="ConditionalFormatting">
    <Page.Resources>
        <local:ForegroundConverter x:Key="ForegroundConverter" />
        <local:BackgroundConverter x:Key="BackgroundConverter" />
        <Point x:Key="OrderTotalRange" X="5000" Y="5000" />
        <Point x:Key="OrderCountRange" X="50" Y="50" />
    </Page.Resources>
    <Grid>
        <c1:C1FlexGrid x:Name="grid" AutoGenerateColumns="False" GridLinesBrush="LightGray" GridLinesVisibility="All" RowBackground="White">
            <c1:C1FlexGrid.Columns>
                <c1:Column Binding="{Binding FirstName}"/>
                <c1:Column Binding="{Binding LastName}"/>
                <c1:Column Binding="{Binding OrderTotal}" Format="C2">
                    <c1:Column.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding OrderTotal, StringFormat=n0}" TextAlignment="Right" HorizontalAlignment="Stretch" Foreground="{Binding OrderTotal, Converter={StaticResource ForegroundConverter}, ConverterParameter={StaticResource OrderTotalRange} }" />
                        </DataTemplate>
                    </c1:Column.CellTemplate>
                </c1:Column>
                <c1:Column Binding="{Binding OrderCount}" Format="N1">
                    <c1:Column.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding OrderCount, StringFormat=n0}" TextAlignment="Right" HorizontalAlignment="Stretch" Background="{Binding OrderCount, Converter={StaticResource BackgroundConverter}, ConverterParameter={StaticResource OrderCountRange} }" />
                        </DataTemplate>
                    </c1:Column.CellTemplate>
                </c1:Column>
                <c1:Column Binding="{Binding CountryId}" Header="Country"/>
                <c1:Column Binding="{Binding LastOrderDate}" Format="d" />
                <c1:Column Binding="{Binding LastOrderDate}" Header="Last Order Time" Format="t" />
            </c1:C1FlexGrid.Columns>
        </c1:C1FlexGrid>
    </Grid>
</Page>
