<UserControl x:Class="VIZ.Package.Module.GHResourcePanel"
             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:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
             xmlns:dxi="http://schemas.devexpress.com/winfx/2008/xaml/core/internal"
             xmlns:dxgt="http://schemas.devexpress.com/winfx/2008/xaml/grid/themekeys"
             xmlns:fcore="clr-namespace:VIZ.Framework.Core;assembly=VIZ.Framework.Core"
             xmlns:local="clr-namespace:VIZ.Package.Module"
             xmlns:domain="clr-namespace:VIZ.Package.Domain;assembly=VIZ.Package.Domain"
             xmlns:resource="clr-namespace:VIZ.Package.Module.Resource;assembly=VIZ.Package.Module.Resource"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance Type=local:GHResourcePanelModel}" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/VIZ.Package.Module.Resource;component/DevExpreess/GridControl/GridControl_Files.xaml"></ResourceDictionary>
                <ResourceDictionary Source="/VIZ.Framework.Common.Resource;component/Style/GridSplitter/GridSplitter_None.xaml"></ResourceDictionary>
                <ResourceDictionary Source="/VIZ.Package.Module.Resource;component/Style/CheckBox/CheckBox_Resource.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
            <fcore:Bitmap2ImageSourceConverter x:Key="Bitmap2ImageSourceConverter"></fcore:Bitmap2ImageSourceConverter>
            <resource:ResourceFileSelectionModeConverter x:Key="ResourceFileSelectionModeConverter">
                <!-- 单选 -->
                <resource:ResourceFileSelectionModeConverter.SingleDataTemplate>
                    <DataTemplate>
                        <Grid Width="120" ClipToBounds="False" UseLayoutRounding="True" Background="Transparent">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="70" />
                                <RowDefinition Height="30" />
                            </Grid.RowDefinitions>
                            <Image Source="{Binding Path=Row.ThumbnailBitmap,Converter={StaticResource Bitmap2ImageSourceConverter}}"></Image>
                            <TextBlock Grid.Row="1" TextAlignment="Center" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" HorizontalAlignment="Center"
                                   Text="{Binding Path=Row.Name}" ToolTip="{Binding Path=Row.Name}" Margin="0,5,0,0"/>
                        </Grid>
                    </DataTemplate>
                </resource:ResourceFileSelectionModeConverter.SingleDataTemplate>
                <!-- 多选 -->
                <resource:ResourceFileSelectionModeConverter.MultipleDataTemplate>
                    <DataTemplate>
                        <Grid Width="120" ClipToBounds="False" UseLayoutRounding="True" Background="Transparent">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="70" />
                                <RowDefinition Height="30" />
                            </Grid.RowDefinitions>
                            <Image Source="{Binding Path=Row.ThumbnailBitmap,Converter={StaticResource Bitmap2ImageSourceConverter}}"></Image>
                            <TextBlock Grid.Row="1" TextAlignment="Center" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" HorizontalAlignment="Center"
                                   Text="{Binding Path=Row.Name}" ToolTip="{Binding Path=Row.Name}" Margin="0,5,0,0"/>
                            <CheckBox Style="{StaticResource ResourceKey=CheckBox_Resource}" Grid.RowSpan="2"
                                      IsChecked="{Binding Path=IsSelected,Mode=OneWay}" IsHitTestVisible="False"></CheckBox>
                        </Grid>
                    </DataTemplate>
                </resource:ResourceFileSelectionModeConverter.MultipleDataTemplate>
            </resource:ResourceFileSelectionModeConverter>
        </ResourceDictionary>
    </UserControl.Resources>

    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:EventToCommand EventName="Loaded" Command="{Binding Path=LoadedCommand}"></dxmvvm:EventToCommand>
    </dxmvvm:Interaction.Behaviors>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="240" MinWidth="240" MaxWidth="400"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <!-- 资源文件夹 -->
        <dxg:TreeViewControl ItemsSource="{Binding Path=FolderModels}" Margin="0,0,5,0"
                             SelectedItem="{Binding Path=SelectedFolderModel,Mode=TwoWay}"
                             ContextMenu="{Binding Path=FolderContextMenu,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:GHResourcePanel}}}"
                             SelectionMode="Row"
                             ShowNodeImages="True" ShowSearchPanel="False"
                             ExpandStateFieldName="IsExpand"
                             AllowEditing="False" TreeViewFieldName="Name" ChildNodesPath="Children">
            <dxmvvm:Interaction.Behaviors>
                <dxmvvm:EventToCommand EventName="NodeDoubleClick" PassEventArgsToCommand="True" Command="{Binding Path=FolderExpandCommand}"></dxmvvm:EventToCommand>
            </dxmvvm:Interaction.Behaviors>
            <dxg:TreeViewControl.NodeImageSelector>
                <local:GHResourceFolderNodeImageSelector Folder="/VIZ.Package.Module.Resource;component/Icons/folder_24x24.png"
                                                         Project="/VIZ.Package.Module.Resource;component/Icons/project_24x24.png"></local:GHResourceFolderNodeImageSelector>
            </dxg:TreeViewControl.NodeImageSelector>
        </dxg:TreeViewControl>

        <!-- 文件夹等待 -->
        <dx:WaitIndicator DeferedVisibility="{Binding IsFolderLoading}" Content="Loading..." Margin="0,0,6,0" />
        <GridSplitter HorizontalAlignment="Right" Width="5" Style="{StaticResource  GridSplitter_None}"></GridSplitter>

        <dxg:GridControl x:Name="fileGrid" Grid.Column="1" ShowBorder="True"
                         ContextMenu="{Binding Path=FileContextMenu,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:GHResourcePanel}}}"
                         SelectionMode="Row"
                         CustomRowFilterCommand="{Binding Path=FileRowFilterCommand}"
                         ItemsSource="{Binding Path=FileModels}" 
                         SelectedItems="{Binding Path=SelectedFileModels,Mode=OneWayToSource}"
                         SelectedItem="{Binding Path=SelectedFileModel,Mode=TwoWay}">
            <dxmvvm:Interaction.Behaviors>
                <dxmvvm:EventToCommand EventName="MouseDoubleClick" Command="{Binding Path=FileDoubleClickCommand}"></dxmvvm:EventToCommand>
            </dxmvvm:Interaction.Behaviors>
            <dxg:GridControl.Columns>
                <dxg:GridColumn FieldName="Name" AllowColumnFiltering="False" AllowEditing="False" ReadOnly="True"></dxg:GridColumn>
            </dxg:GridControl.Columns>
            <dxg:GridControl.View>
                <dxg:CardView IsColumnChooserVisible="False"
                              SeparatorThickness="0"
                              CardLayout="Rows"
                              ShowCardExpandButton="False"
                              ShowColumnHeaders="False"
                              ShowFilterPanelMode="Never"
                              ShowGroupedColumns="False"
                              ShowGroupPanel="False"
                              SearchPanelHighlightResults="False"
                              SearchPanelAllowFilter="True"
                              ShowSearchPanelMode="Never"
                              SearchColumns="Name"
                              NavigationStyle="Row"
                              CardTemplate="{Binding Path=FileSelectionMode,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:GHResourcePanel}},Converter={StaticResource ResourceFileSelectionModeConverter}}"/>

            </dxg:GridControl.View>
        </dxg:GridControl>

        <!-- 文件等待 -->
        <dx:WaitIndicator DeferedVisibility="{Binding IsFileLoading}" Content="Loading..." Grid.Column="1" Grid.Row="1" />
    </Grid>
</UserControl>
