<UserControl x:Class="PDF_Office.Views.BOTA.SearchContent"
             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:local="clr-namespace:PDF_Office.Views.BOTA"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True"
             xmlns:bota="clr-namespace:PDF_Office.ViewModels.BOTA"
             d:DataContext="{d:DesignInstance Type=bota:SearchContentViewModel}"
             xmlns:helper="clr-namespace:PDF_Office.Helper"
              xmlns:convert="clr-namespace:PDF_Office.DataConvert"
             xmlns:customControl="clr-namespace:PDF_Office.CustomControl"
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
   
    <UserControl.Resources>
        <convert:WidthConvert x:Key="WidthConvert"/>
        <convert:BoolToVisible x:Key="BoolToVisible"/>
        <convert:InvertBoolToVisibleConvert x:Key="InvertBoolToVisibleConvert"/>

        <Style x:Key="ListViewItemGraySelectStyle" TargetType="{x:Type ListViewItem}">
            <Setter Property="UIElement.SnapsToDevicePixels"
            Value="True" />
            <Setter Property="Control.Padding"
            Value="4,1" />
            <Setter Property="Control.HorizontalContentAlignment">
                <Setter.Value>
                    <Binding Path="HorizontalContentAlignment"
                     RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}" />
                </Setter.Value>
            </Setter>
            <Setter Property="Control.VerticalContentAlignment">
                <Setter.Value>
                    <Binding Path="VerticalContentAlignment"
                     RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}" />
                </Setter.Value>
            </Setter>
            <Setter Property="Panel.Background"
            Value="#00FFFFFF" />
            <Setter Property="Border.BorderBrush"
            Value="#00FFFFFF" />
            <Setter Property="Border.BorderThickness"
            Value="1" />
            <Setter Property="FrameworkElement.FocusVisualStyle">
                <Setter.Value>
                    <Style TargetType="{x:Type IFrameworkInputElement}">
                        <Setter Property="Control.Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Rectangle Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
                                       StrokeThickness="1"
                                       StrokeDashArray="1 2"
                                       Margin="2"
                                       SnapsToDevicePixels="True" />
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                        <Border BorderThickness="{TemplateBinding Border.BorderThickness}"
                        Padding="{TemplateBinding Control.Padding}"
                        BorderBrush="{TemplateBinding Border.BorderBrush}"
                        Background="{TemplateBinding Panel.Background}"
                        Name="Bd"
                        SnapsToDevicePixels="True">
                            <ContentPresenter Content="{TemplateBinding ContentControl.Content}"
                                      ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                      ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
                                      HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                      VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                                      SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="UIElement.IsMouseOver" Value="True" />
                                </MultiTrigger.Conditions>
                                <Setter Property="Panel.Background" TargetName="Bd" Value="#1A000000" />
                                <Setter Property="Border.BorderBrush" TargetName="Bd" Value="#1A000000" />
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="Selector.IsSelectionActive" Value="False" />
                                    <Condition Property="Selector.IsSelected" Value="True" />
                                </MultiTrigger.Conditions>
                                <Setter Property="Panel.Background" TargetName="Bd" Value="#1A477EDE" />
                                <Setter Property="Border.BorderBrush" TargetName="Bd" Value="#1A477EDE" />
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="Selector.IsSelectionActive" Value="True" />
                                    <Condition Property="Selector.IsSelected" Value="True" />
                                </MultiTrigger.Conditions>
                                <Setter Property="Panel.Background" TargetName="Bd" Value="#1A477EDE" />
                                <Setter Property="Border.BorderBrush" TargetName="Bd" Value="#1A477EDE" />
                            </MultiTrigger>
                            <Trigger Property="UIElement.IsEnabled"  Value="False">
                                <Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid Background="#F3F3F3" Width="200">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>

        <Grid Height="48" Margin="10,0,10,0">
            <TextBlock Text="查找"  HorizontalAlignment="Left" VerticalAlignment="Center"/>
            <Button Content="完成" HorizontalAlignment="Right" VerticalAlignment="Center" Command="{Binding SearchTextCommand}"/>
        </Grid>

        <TextBox Grid.Row="1" Margin="0,0,0,10" Width="180" Height="32" HorizontalAlignment="Center" 
               Text="{Binding SearchContent,Mode=TwoWay}"
                 />

        <Grid Grid.Row="2" Margin="10,0,10,0" Visibility="{Binding IsEmpty ,Converter={StaticResource InvertBoolToVisibleConvert}}">
            <TextBlock  Margin="0,0,0,10"  Text="All Result" VerticalAlignment="Center" HorizontalAlignment="Left"/>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <TextBlock  Margin="0,0,0,10"  Text="Results:" VerticalAlignment="Center" HorizontalAlignment="Right"/>
                <TextBlock x:Name="TbCount"  Margin="0,0,0,10"  Text="{Binding SearchCount}" VerticalAlignment="Center" HorizontalAlignment="Right"/>
            </StackPanel>
            
        </Grid>
        <Grid Grid.Row="3">
            <ListView  Name="SearchResultList" VirtualizingPanel.IsVirtualizingWhenGrouping="True" 
                              ItemsSource="{Binding searchResults,Mode=OneWay}"
                              BorderThickness="0" ItemContainerStyle="{StaticResource ListViewItemGraySelectStyle}"
                              Visibility="{Binding IsEmpty ,Converter={StaticResource InvertBoolToVisibleConvert}}"
                              SelectionChanged="SearchResultList_SelectionChanged"
                              ScrollViewer.HorizontalScrollBarVisibility="Hidden">
                <ListView.GroupStyle>
                    <GroupStyle>
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Grid Background="#E2E3E6" Height="24" >
                                    <TextBlock Padding="0,4,12,4" VerticalAlignment="Stretch" TextAlignment="Center" HorizontalAlignment="Center" FontWeight="SemiBold" FontSize="12" Text="{Binding Name}" 
                                                        FontFamily="Segoe UI" Foreground="#666666 "/>
                                    <customControl:CustomIconToggleBtn x:Name="BtnExptend" Height="24" Click="BtnExptend_Click" 
                                                                       HorizontalAlignment="Right"
                                                                      Style="{StaticResource ToggleBtnViewModeStyle}">
                                        <TextBlock Text="展开" VerticalAlignment="Center"/>
                                    </customControl:CustomIconToggleBtn>
                                </Grid>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                        <GroupStyle.Panel>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel/>
                            </ItemsPanelTemplate>
                        </GroupStyle.Panel>
                    </GroupStyle>
                </ListView.GroupStyle>
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel Background="White" Margin="-5,0,0,0"></VirtualizingStackPanel>
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
                <ListView.ItemTemplate>
                    <ItemContainerTemplate>
                        <StackPanel>
                            <RichTextBox Background="Transparent" Foreground="#000000" FontFamily="Segoe UI" FontSize="14" IsReadOnly="True" BorderThickness="0" 
                                                 Padding="12,6,10,6" VerticalContentAlignment="Center" VerticalAlignment="Center"
                                         helper:RichTextBoxHelper.DocumentBind="{Binding BindProperty}"
                                         Width="{Binding ElementName=SearchResultList,Path=ActualWidth,Converter={StaticResource WidthConvert}}"
                                                  IsHitTestVisible="False" >
                            </RichTextBox>
                        </StackPanel>
                    </ItemContainerTemplate>
                </ListView.ItemTemplate>

                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="SelectionChanged">
                        <i:InvokeCommandAction Command="{Binding SearchChangedCommand}" CommandParameter="{Binding ElementName=SearchResultList,Path=SelectedItem}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </ListView>
        </Grid>

        <Grid Grid.Row="0" Grid.RowSpan="4" Visibility="{Binding IsEmpty ,Converter={StaticResource BoolToVisible}}">
            <StackPanel VerticalAlignment="Center" >
                <Rectangle Margin="0,0,0,10" Width="140" Height="140" Fill="#D9D9D9" />
                <TextBlock Text="Clik the XXX button below to create a XXX" Foreground="#94989C" Width="180" FontFamily="SF Pro Text" LineHeight="22" FontSize="14" TextAlignment="Center" TextWrapping="Wrap"/>
            </StackPanel>
            
        </Grid>
    </Grid>
</UserControl>