<UserControl x:Class="DataGridSamples.CustomFilters"
    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:c1="http://schemas.componentone.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:DataGridSamples"
    d:DataContext="{d:DesignData Source=/DesignData/SampleProducts.xaml}"
    mc:Ignorable="d">
    <UserControl.Resources>
        <Style x:Key="ToggleButtonStyle1" TargetType="ToggleButton">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToggleButton">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard/>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="0.31" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="CheckStates">
                                    <VisualState x:Name="Checked">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="check">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="rectangle">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Collapsed</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="rectangle_Copy">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unchecked"/>
                                    <VisualState x:Name="Indeterminate"/>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement"/>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="Background" Margin="{TemplateBinding Padding}" Background="White">
                                <Grid>
                                    <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}"/>
                                    <Rectangle x:Name="rectangle" StrokeThickness="0" Fill="#7FFFFFFF"/>
                                    <Rectangle x:Name="DisabledVisualElement" Fill="#FFFFFFFF" IsHitTestVisible="false" Opacity="0"/>
                                    <Grid x:Name="check" Width="12" Height="12" VerticalAlignment="Top" HorizontalAlignment="Right" Visibility="Collapsed">
                                        <Rectangle Fill="#FF7693B4" RadiusX="1" RadiusY="1"/>
                                        <Path Data="M0,4.5601196 L3.7081687,8.2193193 C6.4181581,2.4164107 7.4595108,1.1478714 9.656106,0.12681559 C6.990902,-0.48518074 5.4288731,1.1637959 3.2903109,5.7773609 L2.2966058,4.1259389 z" Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" Height="8.22" Width="9.656"/>
                                    </Grid>
                                    <Rectangle x:Name="rectangle_Copy" Stroke="#FF7693B4" Visibility="Collapsed" RadiusX="1" RadiusY="1"/>
                                    <Rectangle x:Name="FocusVisualElement" IsHitTestVisible="false" Opacity="0" Stroke="#FF6DBDD1"/>
                                </Grid>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ToggleValuesFilterStyle" TargetType="local:DataGridToggleValuesFilter">
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <c1:C1WrapPanel ItemWidth="50" ItemHeight="50" Width="200"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemStyle" Value="{StaticResource ToggleButtonStyle1}"/>
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid>
                            <Grid.Resources>
                                <local:ImageSourceConverter x:Key="imageConverter"/>
                            </Grid.Resources>
                            <Image Source="{Binding Converter={StaticResource imageConverter}, ConverterParameter=/DataGridSamples.4;component/Resources/}"/>
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <c1:C1DataGrid 
            x:Name="grid" 
            AutoGenerateColumns="False"
            CanUserAddRows="False" 
            RowHeight="50"
            ItemsSource="{Binding}">
            <c1:C1DataGrid.Resources>
                <local:ImageSourceConverter x:Key="imageConverter"/>
                <local:ImageFilterConverter x:Key="imageFilterConverter"/>
                <local:TreeFilterConverter x:Key="treeFilterConverter"/>
            </c1:C1DataGrid.Resources>
            <c1:C1DataGrid.Columns>
                <c1:DataGridImageColumn Header ="Filter images" 
                                        Binding="{Binding ImageUrl,Converter={StaticResource imageConverter},ConverterParameter=/DataGridSamples.4;component/Resources/}" 
                                        FilterMemberPath="ImageUrl" 
                                        FilterLoading="DataGridImageColumn_FilterLoading"
                                        Width="85">
                    <c1:DataGridImageColumn.Filter>
                        <c1:DataGridContentFilter>
                            <local:DataGridToggleValuesFilter Style="{StaticResource ToggleValuesFilterStyle}" MaxHeight="300"/>
                        </c1:DataGridContentFilter>
                    </c1:DataGridImageColumn.Filter>
                </c1:DataGridImageColumn>
                <c1:DataGridTextColumn Header="Tree filter" 
                                       Binding="{Binding ProductNumber}" 
                                       FilterMemberPath="ProductNumber"
                                       FilterLoading="DataGridTextColumn_FilterLoading">
                    <c1:DataGridTextColumn.Filter>
                        <c1:DataGridContentFilter>
                            <c1:DataGridFilterList>
                                <local:DataGridTreeViewFilter/>
                                <c1:DataGridTextFilter/>
                            </c1:DataGridFilterList>
                        </c1:DataGridContentFilter>
                    </c1:DataGridTextColumn.Filter>
                </c1:DataGridTextColumn>
                <c1:DataGridNumericColumn Header="Histogram filter" 
                                          Binding="{Binding StandardCost}"
                                          FilterMemberPath="StandardCost"
                                          FilterLoading="DataGridNumericColumn_FilterLoading">
                    <c1:DataGridNumericColumn.Filter>
                        <c1:DataGridContentFilter>
                            <c1:DataGridFilterList>
                                <local:DataGridHistogramFilter Width="230" 
                                                               Height="80"
                                                               BinCount="200"
                                                               ValueMemberPath="StandardCost"/>
                                <c1:DataGridNumericFilter/>
                                <c1:DataGridTextFilter/>
                            </c1:DataGridFilterList>
                        </c1:DataGridContentFilter>
                    </c1:DataGridNumericColumn.Filter>
                </c1:DataGridNumericColumn>
                <c1:DataGridNumericColumn Header="Filters inside a tab control" 
                                          Binding="{Binding StandardCost}"
                                          FilterMemberPath="StandardCost"
                                          Format="C">
                    <c1:DataGridNumericColumn.Filter>
                        <c1:DataGridContentFilter>
                            <local:DataGridTabFilters Width="250">
                                <local:DataGridNumericRangeFilter Minimum="0"
                                                           Maximum="1000"
                                                           Format="C"/>
                                <c1:DataGridMultiLineNumericFilter Format="C"/>
                                <c1:DataGridMultiLineTextFilter/>
                            </local:DataGridTabFilters>
                        </c1:DataGridContentFilter>
                    </c1:DataGridNumericColumn.Filter>
                </c1:DataGridNumericColumn>
                <c1:DataGridDateTimeColumn Header="Date filter"
                                           Binding="{Binding ExpirationDate}"
                                           FilterMemberPath="ExpirationDate"
                                           FilterLoading="DataGridDateTimeColumn_FilterLoading">
                    <c1:DataGridDateTimeColumn.Filter>
                        <c1:DataGridContentFilter>
                            <c1:DataGridFilterList>
                                <local:DataGridDateRangeFilter/>
                                <c1:DataGridDateTimeFilter/>
                                <c1:DataGridTextFilter/>
                            </c1:DataGridFilterList>
                        </c1:DataGridContentFilter>
                    </c1:DataGridDateTimeColumn.Filter>
                </c1:DataGridDateTimeColumn>
                <local:DataGridColorColumn Header="Filtering colors" 
                                           Binding="{Binding Color, Mode=TwoWay}" 
                                           FilterMemberPath="Color">
                    <local:DataGridColorColumn.CellContentStyle>
                        <Style TargetType="c1:C1CheckeredBorder">
                            <Setter Property="MaxHeight" Value="24"/>
                            <Setter Property="MaxWidth" Value="50"/>
                        </Style>
                    </local:DataGridColorColumn.CellContentStyle>
                    <local:DataGridColorColumn.CellEditingContentStyle>
                        <Style TargetType="c1:C1ColorPicker">
                            <Setter Property="MaxHeight" Value="24"/>
                            <Setter Property="MaxWidth" Value="50"/>
                        </Style>
                    </local:DataGridColorColumn.CellEditingContentStyle>
                </local:DataGridColorColumn>
            </c1:C1DataGrid.Columns>
        </c1:C1DataGrid>
    </Grid>
</UserControl>
