<UserControl x:Class="DateTimeFiltering.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    xmlns:themes="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:local="clr-namespace:DateTimeFiltering"
    xmlns:jeff="clr-namespace:JeffWilcox.Samples;assembly=HighlightingTextBlock">
    
    <UserControl.Resources>
        <local:SearchViewModel x:Key="ViewModel" />

        <SolidColorBrush Color="Red" x:Key="HighlightBrush" />
        <Style TargetType="jeff:HighlightingTextBlock" x:Key="HighlightTextBlockStyle">
            <Setter Property="HighlightBrush" Value="{StaticResource HighlightBrush}" />
            <Setter Property="HighlightFontWeight" Value="Bold" />
        </Style>

        <DataTemplate x:Key="HighlightCellTemplate">
            <jeff:HighlightingTextBlock 
                Style="{StaticResource HighlightTextBlockStyle}" 
                HighlightText="{Binding SearchText, Source={StaticResource ViewModel}}" >
                <i:Interaction.Behaviors>
                    <local:CellValueBindingBehavior />
                </i:Interaction.Behaviors>
            </jeff:HighlightingTextBlock>
        </DataTemplate>
    </UserControl.Resources>
    
    <Grid DataContext="{Binding Source={StaticResource ViewModel}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
            
        <TextBlock Text="Find:" Margin="5,5,7,5" VerticalAlignment="Center"/>            
        <TextBox x:Name="textBoxFilterValue" Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=Explicit}" Grid.Column="1" Margin="3">
            <i:Interaction.Behaviors>
                <local:PropertyChangedUpdateTriggerBehavior />
            </i:Interaction.Behaviors>
        </TextBox>

        <telerik:RadGridView Name="playersGrid" AutoGenerateColumns="False" ItemsSource="{Binding Items}"
            local:CustomFilterBehavior.TextBox="{Binding ElementName=textBoxFilterValue}"
            Grid.Row="1" Grid.ColumnSpan="2">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" CellTemplate="{StaticResource HighlightCellTemplate}" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}" CellTemplate="{StaticResource HighlightCellTemplate}" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}" CellTemplate="{StaticResource HighlightCellTemplate}" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</UserControl>