<UserControl x:Class="VIZ.Package.Module.PageTemplateView"
             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:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
             xmlns:fcore="clr-namespace:VIZ.Framework.Core;assembly=VIZ.Framework.Core"
             xmlns:fcommon="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common"
             xmlns:common="clr-namespace:VIZ.Package.Common;assembly=VIZ.Package.Common"
             xmlns:storage="clr-namespace:VIZ.Package.Storage;assembly=VIZ.Package.Storage"
             xmlns:resource="clr-namespace:VIZ.Package.Module.Resource;assembly=VIZ.Package.Module.Resource"
             xmlns:local="clr-namespace:VIZ.Package.Module"
             xmlns:domain="clr-namespace:VIZ.Package.Domain;assembly=VIZ.Package.Domain"
             d:DataContext="{d:DesignInstance Type=local:PageTemplateViewModel}" 
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <resource:RowHandleConverter x:Key="RowHandleConverter"></resource:RowHandleConverter>
            <fcore:Bitmap2ImageSourceConverter x:Key="Bitmap2ImageSourceConverter"></fcore:Bitmap2ImageSourceConverter>
            <fcore:Enum2EnumDescriptionConverter x:Key="Enum2EnumDescriptionConverter" EnumType="{x:Type storage:PageType}"></fcore:Enum2EnumDescriptionConverter>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid IsEnabled="{Binding Path=IsEnabled}" Margin="0,10,0,10">
        <dxg:GridControl ItemsSource="{Binding Path=SceneTemplateModels}" ShowBorder="False" SelectionMode="Row"
                         SelectedItems="{Binding Path=SelectedSceneTemplateModels,Mode=OneWayToSource}">
            <dxg:GridControl.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="打开" Command="{Binding Path=PlacementTarget.DataContext.OpenScenePageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <Separator></Separator>
                    <MenuItem Header="添加至节目单" Command="{Binding Path=PlacementTarget.DataContext.AddToPageGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <MenuItem Header="更新模板" Command="{Binding Path=PlacementTarget.DataContext.UpdateCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <Separator></Separator>
                    <MenuItem Header="删除模板" Command="{Binding Path=PlacementTarget.DataContext.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                </ContextMenu>
            </dxg:GridControl.ContextMenu>
            <dxg:GridControl.Columns>
                <common:GridColumnResizeMinHeight Header="缩略图" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False" 
                                                  AllowEditing="False" Width="120" MinWidth="40" MaxWidth="300" AllowResizing="True">
                    <common:GridColumnResizeMinHeight.CellTemplate>
                        <DataTemplate>
                            <fcommon:ResizeImageControl ImageSource="{Binding Path=Row.ThumbnailBitmap,Converter={StaticResource Bitmap2ImageSourceConverter}}"
                                                                IconSource="/VIZ.Package.Module.Resource;component/Icons/image_20x20.png"
                                                                ShowImageMinWidth="50" ShowImageMinHeight="50"></fcommon:ResizeImageControl>
                        </DataTemplate>
                    </common:GridColumnResizeMinHeight.CellTemplate>
                </common:GridColumnResizeMinHeight>
                <dxg:GridColumn Header="场景名" FieldName="Scene" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"></dxg:GridColumn>
                <dxg:GridColumn Header="备注" FieldName="Remark" AllowSorting="False" AllowColumnFiltering="False">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings TextWrapping="Wrap" TextTrimming="CharacterEllipsis" MaxLength="50"></dxe:TextEditSettings>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn Header="层" FieldName="Layer" AllowSorting="False" AllowColumnFiltering="False">
                    <dxg:GridColumn.EditSettings>
                        <dxe:ComboBoxEditSettings ItemsSource="{Binding Source={x:Static domain:ApplicationConstants.VIZ_LAYERS}}"
                                                          IsTextEditable="False"></dxe:ComboBoxEditSettings>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn Header="引擎类型" FieldName="EngineType" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"></dxg:GridColumn>
            </dxg:GridControl.Columns>
            <dxg:GridControl.View>
                <dxg:TableView IsColumnMenuEnabled="False" RowMinHeight="69.5"
                               AllowEditing="True" ShowIndicator="False"
                               NavigationStyle="Cell" ShowVerticalLines="False"
                               ShowGroupPanel="False" EditorShowMode="MouseDown"
                               AllowDragDrop="True"
                               ShowBandsPanel="False"
                               ShowTotalSummary="False"
                               ShowFixedTotalSummary="False"
                               ShowDragDropHint="False"
                               ShowTargetInfoInDragDropHint="false">
                    <dxmvvm:Interaction.Behaviors>
                        <dxmvvm:EventToCommand EventName="RowDoubleClick" Command="{Binding Path=OpenScenePageCommand}"></dxmvvm:EventToCommand>
                    </dxmvvm:Interaction.Behaviors>
                </dxg:TableView>
            </dxg:GridControl.View>
        </dxg:GridControl>

        <dx:WaitIndicator DeferedVisibility="{Binding IsLoading}" Content="Loading..." />
    </Grid>
</UserControl>
