<UserControl x:Class="VIZ.Package.Module.MediaResourcePanel"
             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"
             mc:Ignorable="d"
             d:DataContext="{d:DesignInstance Type=local:MediaResourcePanelViewModel}" 
             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.MergedDictionaries>
            <fcore:Bitmap2ImageSourceConverter x:Key="Bitmap2ImageSourceConverter"></fcore:Bitmap2ImageSourceConverter>
        </ResourceDictionary>
    </UserControl.Resources>

    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:EventToCommand EventName="Loaded" Command="{Binding Path=LoadedCommand}"></dxmvvm:EventToCommand>
    </dxmvvm:Interaction.Behaviors>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" MinWidth="240" MaxWidth="400"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
  
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <!--<RowDefinition Height="30"></RowDefinition>-->
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <!-- 资源文件夹 -->
        <dxg:TreeViewControl ItemsSource="{Binding Path=FolderModels}" Margin="0,0,6,0" Grid.Row="0"
                             SelectedItem="{Binding Path=SelectedFolderModel,Mode=TwoWay}"
                             SelectionMode="Row" ShowNodeImages="True" ShowSearchPanel="False"
                             ContextMenu="{Binding Path=FolderContextMenu,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:MediaResourcePanel}}}"
                             ExpandStateFieldName="IsExpand"
                             AllowEditing="False" TreeViewFieldName="Name" ChildNodesPath="Children">
            <!--<dxg:TreeViewControl.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="刷新" Command="{Binding Path=PlacementTarget.DataContext.RefreshFolderCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <MenuItem Header="创建文件夹" Command="{Binding Path=PlacementTarget.DataContext.CreateFloderCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <MenuItem Header="删除文件夹" Command="{Binding Path=PlacementTarget.DataContext.DeleteFloderCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <MenuItem Header="移入文件夹" Command="{Binding Path=PlacementTarget.DataContext.MoveFloderCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                </ContextMenu>
            </dxg:TreeViewControl.ContextMenu>-->
            <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..." Grid.Row="1" Margin="0,0,6,0" />
        <GridSplitter HorizontalAlignment="Right" Width="4" Grid.Row="0"></GridSplitter>

        <!-- 资源文件 -->
        <!--<StackPanel Grid.Column="1" Orientation="Horizontal">
            <RadioButton Height="30" Width="60" Content="All" IsChecked="True">
                <dxmvvm:Interaction.Behaviors>
                    <dxmvvm:EventToCommand EventName="Checked" Command="{Binding Path=FileFilterCommand}" CommandParameter="{x:Static Member=domain:ResourceFileType.None}"></dxmvvm:EventToCommand>
                </dxmvvm:Interaction.Behaviors>
            </RadioButton>

            <RadioButton Height="30" Width="60" Content="场景">
                <dxmvvm:Interaction.Behaviors>
                    <dxmvvm:EventToCommand EventName="Checked" Command="{Binding Path=FileFilterCommand}" CommandParameter="{x:Static Member=domain:ResourceFileType.SCENE}"></dxmvvm:EventToCommand>
                </dxmvvm:Interaction.Behaviors>
            </RadioButton>

            <RadioButton Height="30" Width="60" Content="图片">
                <dxmvvm:Interaction.Behaviors>
                    <dxmvvm:EventToCommand EventName="Checked" Command="{Binding Path=FileFilterCommand}" CommandParameter="{x:Static Member=domain:ResourceFileType.IMAGE}"></dxmvvm:EventToCommand>
                </dxmvvm:Interaction.Behaviors>
            </RadioButton>
            <RadioButton Height="30" Width="60" Content="视频">
                <dxmvvm:Interaction.Behaviors>
                    <dxmvvm:EventToCommand EventName="Checked" Command="{Binding Path=FileFilterCommand}" CommandParameter="{x:Static Member=domain:ResourceFileType.Video}"></dxmvvm:EventToCommand>
                </dxmvvm:Interaction.Behaviors>
            </RadioButton>
        </StackPanel>-->
        <dxg:GridControl x:Name="fileGrid" Grid.Column="1" ShowBorder="False" Grid.Row="0" Visibility="{Binding VisibilityImage,Mode=TwoWay}"
                         CustomRowFilterCommand="{Binding Path=FileRowFilterCommand}"
                         ItemsSource="{Binding Path=FileModels}"
                         SelectedItem="{Binding Path=SelectedFileModel,Mode=TwoWay}"
                         ContextMenu="{Binding Path=FileContextMenu,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:MediaResourcePanel}}}">
            
            <dxmvvm:Interaction.Behaviors>
                <dxmvvm:EventToCommand EventName="MouseDoubleClick" Command="{Binding Path=FileDoubleClickCommand}"></dxmvvm:EventToCommand>
            </dxmvvm:Interaction.Behaviors>
            <dxg:GridControl.Resources>
                <!-- 定义Card模板 -->
                <DataTemplate x:Key="CardTemplate">
                    <!--<common:ResourceDragBorder Background="Transparent">-->
                    <Grid Width="160" ClipToBounds="False" UseLayoutRounding="True" >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="90" />
                            <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>
                    <!--</common:ResourceDragBorder>-->
                </DataTemplate>
            </dxg:GridControl.Resources>
            
            <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="{StaticResource CardTemplate}"/>
            </dxg:GridControl.View>
        </dxg:GridControl>

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


        <dxg:GridControl x:Name="FileList" ShowBorder="False" ItemsSource="{Binding Path= FileModels,Mode=TwoWay}" Visibility="{Binding VisibilityList, Mode=TwoWay}" Grid.Column="1"
                         ContextMenu="{Binding Path=FileListContextMenu,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type local:MediaResourcePanel}}}" >
            
            <dxg:GridColumn FieldName="Name"  Header="文件名" Width="100" />
                        <dxg:GridColumn FieldName="FileType"  Header="类型" Width="100"/>
                        <dxg:GridColumn FieldName="Date"  Header="日期" Width="130"/>
            <dxg:GridColumn FieldName="FileSize"  Header="大小" Width="130"/>
            <!--#endregion-->
            <dxg:GridControl.View>
                <dxg:TableView AutoWidth="True"  ShowGroupPanel="False"  ShowVerticalLines="False" ShowHorizontalLines="False"
                               BorderThickness="0"  
                               ShowFilterPanelMode="Never" 
                               AllowColumnFiltering="False"
                               AllowSorting="False"
                               AllowEditing="False"  >
                </dxg:TableView>
            </dxg:GridControl.View>
        </dxg:GridControl>
      
    </Grid>
</UserControl>
