<UserControl x:Class="VIZ.Package.Module.PageGroupView"
             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:dxdo="http://schemas.devexpress.com/winfx/2008/xaml/docking"
             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:PageGroupViewModel}" 
             x:Name="uc"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">

    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:EventToCommand EventName="PreviewKeyDown" Command="{Binding Path=PreviewKeyDownCommand}" PassEventArgsToCommand="True"></dxmvvm:EventToCommand>
    </dxmvvm:Interaction.Behaviors>

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/VIZ.Package.Module.Resource;component/Style/IconButton/IconButton_Default.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>

            <resource:RowHandleConverter x:Key="RowHandleConverter"></resource:RowHandleConverter>
            <resource:PageThumbnailMultiConverter x:Key="PageThumbnailMultiConverter"
                                                  CommandThumbnail="/VIZ.Package.Module.Resource;component/Images/cmd_template.png"></resource:PageThumbnailMultiConverter>
            <fcore:Bitmap2ImageSourceConverter x:Key="Bitmap2ImageSourceConverter"></fcore:Bitmap2ImageSourceConverter>
            <fcore:Enum2EnumDescriptionConverter x:Key="Enum2EnumDescriptionConverter" EnumType="{x:Type storage:PageType}"></fcore:Enum2EnumDescriptionConverter>
            <fcore:Bool2SolidColorBrushConverter x:Key="RowHandleBgConverter"
                                                 TrueBrush="#FF0078D7"
                                                 FalseBrush="Transparent"></fcore:Bool2SolidColorBrushConverter>
            <fcore:Bool2SolidColorBrushConverter x:Key="RowHandleTakeConverter"
                                                 TrueBrush="#FF67ad5b"
                                                 FalseBrush="Transparent"></fcore:Bool2SolidColorBrushConverter>
            <fcore:Bool2BoolConverter x:Key="Bool2BoolConverter"></fcore:Bool2BoolConverter>
            <fcore:MultiBool2BoolConverter x:Key="MultiBool2BoolConverter" Mask="1 0" MatchResult="True" NotMatchResult="False"></fcore:MultiBool2BoolConverter>

            <!-- 层模板 -->
            <fcore:Bool2ControlTemplateConverter x:Key="Bool2ControlTemplateConverter_LayerColumnCellTemplate">
                <fcore:Bool2ControlTemplateConverter.TrueResult>
                    <ControlTemplate>
                        <Border Background="Transparent">
                            <TextBlock Text="{Binding Path=Row.LayerIdentifier}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="4,0,4,0"></TextBlock>
                            <Border.ToolTip>
                                <Grid Height="75" MinWidth="220">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="110"></ColumnDefinition>
                                        <ColumnDefinition Width="*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Row="0" Grid.Column="0" Text="Layer identifier:" Foreground="#88ffffff" HorizontalAlignment="Right"></TextBlock>
                                    <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Row.LayerIdentifier,Mode=OneWay}" Margin="10,0,10,0"></TextBlock>
                                    <TextBlock Grid.Row="1" Grid.Column="0" Text="State identifier:" Foreground="#88ffffff" HorizontalAlignment="Right"></TextBlock>
                                    <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Row.StateIdentifier,Mode=OneWay}" Margin="10,0,10,0"></TextBlock>
                                    <TextBlock Grid.Row="2" Grid.Column="0" Text="Background scene:" Foreground="#88ffffff" HorizontalAlignment="Right"></TextBlock>
                                    <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Path=Row.BackgroundScene,Mode=OneWay}" Margin="10,0,10,0"></TextBlock>
                                </Grid>
                            </Border.ToolTip>
                        </Border>
                    </ControlTemplate>
                </fcore:Bool2ControlTemplateConverter.TrueResult>
                <fcore:Bool2ControlTemplateConverter.FalseResult>
                    <ControlTemplate>
                        <TextBlock Text="{Binding Path=Row.Layer}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="4,0,4,0"></TextBlock>
                    </ControlTemplate>
                </fcore:Bool2ControlTemplateConverter.FalseResult>
            </fcore:Bool2ControlTemplateConverter>

            <fcore:Bool2ControlTemplateConverter x:Key="Bool2ControlTemplateConverter_LayerColumnCellEditTemplate">
                <fcore:Bool2ControlTemplateConverter.TrueResult>
                    <ControlTemplate>
                        <Border Background="Transparent">
                            <TextBlock Text="{Binding Path=Row.LayerIdentifier}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="4,0,4,0"></TextBlock>
                            <Border.ToolTip>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                        <RowDefinition Height="*"></RowDefinition>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="80"></ColumnDefinition>
                                        <ColumnDefinition Width="*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Row="0" Grid.Column="0" Text="Layer identifier:" Foreground="#aaffffff"></TextBlock>
                                    <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Row.LayerIdentifier,Mode=OneWay}"></TextBlock>
                                    <TextBlock Grid.Row="1" Grid.Column="0" Text="State identifier:" Foreground="#aaffffff"></TextBlock>
                                    <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Row.StateIdentifier,Mode=OneWay}"></TextBlock>
                                    <TextBlock Grid.Row="2" Grid.Column="0" Text="Background scene:" Foreground="#aaffffff"></TextBlock>
                                    <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Path=Row.BackgroundScene,Mode=OneWay}"></TextBlock>
                                </Grid>
                            </Border.ToolTip>
                        </Border>
                    </ControlTemplate>
                </fcore:Bool2ControlTemplateConverter.TrueResult>
                <fcore:Bool2ControlTemplateConverter.FalseResult>
                    <ControlTemplate>
                        <dxe:ComboBoxEdit ItemsSource="{Binding Source={x:Static domain:ApplicationConstants.VIZ_LAYERS}}"
                                          EditValue="{Binding Path=Row.Layer,Mode=TwoWay}" ShowBorder="False"
                                          IsTextEditable="False"></dxe:ComboBoxEdit>
                    </ControlTemplate>
                </fcore:Bool2ControlTemplateConverter.FalseResult>
            </fcore:Bool2ControlTemplateConverter>

            <!-- 列模板选择器 -->
            <common:ColumnDefintionGeneratorTemplateSelector x:Key="ColumnDefintionGeneratorTemplateSelector">
                <common:ColumnDefintionGeneratorTemplateSelector.Templates>
                    <common:ColumnDefintionGeneratorTemplateCollection>
                        <!-- 序号 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="Index">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="序号" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False" Width="40" AllowResizing="False">
                                            <dxg:GridColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Grid>
                                                        <Rectangle Fill="{Binding Path=Row.IsTake,Converter={StaticResource RowHandleTakeConverter}}"></Rectangle>
                                                        <TextBlock Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding RowData.RowHandle,Converter={StaticResource RowHandleConverter}}"></TextBlock>
                                                    </Grid>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellTemplate>
                                        </dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 编号 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="PageNum">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="ID" AllowSorting="False" AllowColumnFiltering="False" AllowResizing="True"
                                                        FieldName="PageNum"
                                                        Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                        VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}">
                                            <dxg:GridColumn.CellTemplate>
                                                <DataTemplate>
                                                    <TextBlock Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="4,0,4,0"
                                                               Text="{Binding Row.PageNum,StringFormat={}{0:D4}}"></TextBlock>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellTemplate>
                                            <dxg:GridColumn.CellEditTemplate>
                                                <DataTemplate>
                                                    <local:PageNumberEdit></local:PageNumberEdit>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellEditTemplate>
                                        </dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 缩略图 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="ThumbnailBitmap">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <common:GridColumnResizeMinHeight Header="缩略图" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                                                          AllowEditing="False" Width="120" MinWidth="40" MaxWidth="300" AllowResizing="True"
                                                                          Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                                          VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}">
                                            <common:GridColumnResizeMinHeight.CellTemplate>
                                                <DataTemplate>
                                                    <fcommon:ResizeImageControl IconSource="/VIZ.Package.Module.Resource;component/Icons/image_20x20.png"
                                                                                ShowImageMinWidth="30" ShowImageMinHeight="30">
                                                        <fcommon:ResizeImageControl.ImageSource>
                                                            <MultiBinding Converter="{StaticResource PageThumbnailMultiConverter}">
                                                                <Binding Path="Row.ThumbnailBitmap"/>
                                                                <Binding Path="Row.PageType"/>
                                                            </MultiBinding>
                                                        </fcommon:ResizeImageControl.ImageSource>
                                                    </fcommon:ResizeImageControl>
                                                </DataTemplate>
                                            </common:GridColumnResizeMinHeight.CellTemplate>
                                        </common:GridColumnResizeMinHeight>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 场景名 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="Scene">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="场景名" FieldName="Scene" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                                        Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                        VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}"></dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 备注 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="Remark">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="备注"  FieldName="Remark" AllowSorting="False" AllowColumnFiltering="False"
                                                        Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                        VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}">
                                            <dxg:GridColumn.EditSettings>
                                                <dxe:TextEditSettings TextWrapping="Wrap" TextTrimming="CharacterEllipsis" MaxLength="50"></dxe:TextEditSettings>
                                            </dxg:GridColumn.EditSettings>
                                        </dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 层 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="Layer">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="层" AllowSorting="False" AllowColumnFiltering="False"
                                                        Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                        VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}"
                                                        AllowEditing="True">
                                            <dxg:GridColumn.CellTemplate>
                                                <DataTemplate>
                                                    <ContentControl Template="{Binding Path=Row.TransitionLogic,Converter={StaticResource Bool2ControlTemplateConverter_LayerColumnCellTemplate}}"></ContentControl>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellTemplate>
                                            <dxg:GridColumn.CellEditTemplate>
                                                <DataTemplate>
                                                    <ContentControl Template="{Binding Path=Row.TransitionLogic,Converter={StaticResource Bool2ControlTemplateConverter_LayerColumnCellEditTemplate}}"></ContentControl>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellEditTemplate>
                                        </dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 连接 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="ConnGroupID">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="连接" AllowSorting="False" AllowColumnFiltering="False"
                                                        Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                        VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}">
                                            <dxg:GridColumn.CellTemplate>
                                                <DataTemplate>
                                                    <dxe:ComboBoxEdit ItemsSource="{Binding ElementName=uc, Path=DataContext.ConnGroups,Mode=TwoWay}"
                                                                      EditValue="{Binding Path=Row.ConnGroupID,Mode=TwoWay}" ShowBorder="False" IsReadOnly="True" ShowEditorButtons="False"
                                                                      DisplayMember="Name" ValueMember="GroupID" IsTextEditable="False"></dxe:ComboBoxEdit>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellTemplate>
                                            <dxg:GridColumn.CellEditTemplate>
                                                <DataTemplate>
                                                    <dxe:ComboBoxEdit ItemsSource="{Binding ElementName=uc, Path=DataContext.ConnGroups,Mode=TwoWay}"
                                                                      EditValue="{Binding Path=Row.ConnGroupID,Mode=TwoWay}" ShowBorder="False"
                                                                      DisplayMember="Name" ValueMember="GroupID" IsTextEditable="False"></dxe:ComboBoxEdit>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellEditTemplate>
                                        </dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 初始化加载 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="TakeInitedProgress">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="初始化状态" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False" AllowEditing="False"
                                                        Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                        VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}">
                                            <dxg:GridColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Grid Background="Transparent" ToolTip="{Binding Path=Row.SceneInfo.TakeInitedMessage}">
                                                        <dxe:ProgressBarEdit Minimum="0" Maximum="1" ContentDisplayMode="Value" 
                                                                             DisplayFormatString="{}{0:P}" Height="20" ShowBorder="False" Background="Transparent"
                                                                             EditValue="{Binding Path=Row.SceneInfo.TakeInitedProgress}"></dxe:ProgressBarEdit>
                                                    </Grid>
                                                </DataTemplate>
                                            </dxg:GridColumn.CellTemplate>
                                        </dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 引擎类型 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="EngineType">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="引擎类型" FieldName="EngineType" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                                        Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                        VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}"></dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 模板类型 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="PageType">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="模板类型" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                                        Binding="{Binding Path=PageType,Converter={StaticResource Enum2EnumDescriptionConverter}}"
                                                        Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                        VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}">
                                        </dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                        <!-- 插件 -->
                        <common:ColumnDefintionGeneratorTemplate ColumnKey="PluginName">
                            <common:ColumnDefintionGeneratorTemplate.DataTemplate>
                                <DataTemplate>
                                    <ContentControl>
                                        <dxg:GridColumn Header="数据模板" FieldName="PluginName" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False"
                                                        Visible="{Binding Path=Visible,Mode=TwoWay}"
                                                        VisibleIndex="{Binding Path=VisibleIndex,Mode=TwoWay}"></dxg:GridColumn>
                                    </ContentControl>
                                </DataTemplate>
                            </common:ColumnDefintionGeneratorTemplate.DataTemplate>
                        </common:ColumnDefintionGeneratorTemplate>
                    </common:ColumnDefintionGeneratorTemplateCollection>
                </common:ColumnDefintionGeneratorTemplateSelector.Templates>
            </common:ColumnDefintionGeneratorTemplateSelector>

        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <Grid.IsHitTestVisible>
            <!-- Mask: 1 0 -->
            <MultiBinding Converter="{StaticResource MultiBool2BoolConverter}">
                <Binding Path="IsEnabled"/>
                <Binding Path="IsWaitingPageOpen"/>
            </MultiBinding>
        </Grid.IsHitTestVisible>
        <Grid.RowDefinitions>
            <RowDefinition Height="35"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <!-- 按钮组 -->
        <Border Background="#11FFFFFF">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                <!-- 清理 -->
                <fcommon:IconButton Icon="/VIZ.Package.Module.Resource;component/Icons/icon_clear_32x32.png"
                                    Style="{StaticResource IconButton_Menu_Mask}"
                                    ToolTip="清理内存" Margin="10,0,0,0" 
                                    IconWidth="24" IconHeight="24" Width="24" Height="24"
                                    Command="{Binding TakeClearCommand}"></fcommon:IconButton>
                <!-- 初始化 -->
                <fcommon:IconButton Icon="/VIZ.Package.Module.Resource;component/Icons/icon_init_32x32.png"
                                    Style="{StaticResource IconButton_Menu_Mask}"
                                    ToolTip="初始化" Margin="10,0,0,0" 
                                    IconWidth="24" IconHeight="24" Width="24" Height="24"
                                    Command="{Binding TakeInitAllCommand}"></fcommon:IconButton>
            </StackPanel>
        </Border>

        <dx:DXTabControl Grid.Row="1" Margin="0,10,0,0" Padding="0,5,0,0" 
                         ItemsSource="{Binding Path=PageGroupModels}" Background="Transparent"
                         SelectedItem="{Binding Path=SelectedPageGroupModel,Mode=TwoWay}">
            <dx:DXTabControl.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="新建分组" Command="{Binding Path=PlacementTarget.DataContext.AddGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <MenuItem Header="重命名分组" Command="{Binding Path=PlacementTarget.DataContext.RenameGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <Separator></Separator>
                    <MenuItem Header="复制分组" Command="{Binding Path=PlacementTarget.DataContext.CopyPageGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <Separator></Separator>
                    <MenuItem Header="删除分组" Command="{Binding Path=PlacementTarget.DataContext.DeleteGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                </ContextMenu>
            </dx:DXTabControl.ContextMenu>
            <dx:DXTabControl.View>
                <dx:TabControlStretchView Tag="Stretch"
                                          HeaderLocation="Top" ShowHeaderMenu="False"
                                          NewButtonShowMode="InTabPanel"
                                          HideButtonShowMode="InAllTabs"
                                          PinnedTabSize="100">
                </dx:TabControlStretchView>
            </dx:DXTabControl.View>

            <dxmvvm:Interaction.Behaviors>
                <dxmvvm:EventToCommand EventName="TabAdding" Command="{Binding TabAddGroupCommand}" PassEventArgsToCommand="True" />
            </dxmvvm:Interaction.Behaviors>
            <dx:DXTabControl.ItemContainerStyle>
                <Style TargetType="dx:DXTabItem">
                    <Setter Property="Content" Value="{Binding .}" />
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <dxg:GridControl ItemsSource="{Binding Path=Pages}" ShowBorder="False" IsFilterEnabled="False" SelectionMode="Row" Margin="0,5,0,0"
                                                 SelectedItem="{Binding Path=SelectedPage,Mode=TwoWay}"
                                                 SelectedItems="{Binding Path=SelectedPages}"
                                                 ColumnsSource="{Binding ElementName=uc, Path=DataContext.Columns}"
                                                 ColumnGeneratorTemplateSelector="{StaticResource ResourceKey=ColumnDefintionGeneratorTemplateSelector}">

                                    <dxg:GridControl.Resources>
                                        <Style TargetType="{x:Type dxg:RowControl}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding Row.IsOpen}" Value="True">
                                                    <Setter Property="Background" Value="#990078D7"></Setter>
                                                </DataTrigger>
                                                <MultiDataTrigger>
                                                    <MultiDataTrigger.Conditions>
                                                        <Condition Binding="{Binding Row.IsOpen}" Value="True"></Condition>
                                                        <Condition Binding="{Binding IsActive,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type dxdo:LayoutPanel}}}" Value="True"></Condition>
                                                    </MultiDataTrigger.Conditions>
                                                    <MultiDataTrigger.Setters>
                                                        <Setter Property="Background" Value="#FF0078D7"></Setter>
                                                    </MultiDataTrigger.Setters>
                                                </MultiDataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </dxg:GridControl.Resources>

                                    <dxg:GridControl.ContextMenu>
                                        <common:ContextMenuEx BindingTargetType="{x:Type dx:DXTabControl}">
                                            <MenuItem Header="添加命令页" Command="{Binding Path=DataContext.CreateCmdPageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type common:ContextMenuEx}}}"/>
                                            <Separator></Separator>
                                            <MenuItem Header="粘贴页" Command="{Binding Path=DataContext.PastePageCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type common:ContextMenuEx}}}"/>
                                        </common:ContextMenuEx>
                                    </dxg:GridControl.ContextMenu>

                                    <dxg:GridControl.View>
                                        <dxg:TableView IsColumnMenuEnabled="True"
                                                       IsColumnChooserVisible="{Binding ElementName=uc, Path=DataContext.IsColumnChooserVisible,Mode=TwoWay}"
                                                       AllowEditing="True" ShowIndicator="False" RowMinHeight="69.5"
                                                       NavigationStyle="Cell" ShowVerticalLines="False" ShowHorizontalLines="False"
                                                       ShowGroupPanel="False" EditorShowMode="MouseDown"
                                                       AllowDragDrop="True"
                                                       AlternateRowBackground="#05ffffff"
                                                       ShowBandsPanel="False"
                                                       ShowTotalSummary="False"
                                                       ShowFixedTotalSummary="False" 
                                                       ShowDragDropHint="False" IsVisibleChanged="TableView_IsVisibleChanged"
                                                       ShowTargetInfoInDragDropHint="false">
                                            <dxmvvm:Interaction.Behaviors>
                                                <dxmvvm:EventToCommand EventName="RowDoubleClick" Command="{Binding ElementName=uc, Path=DataContext.OpenPageCommand}"></dxmvvm:EventToCommand>
                                                <dxmvvm:EventToCommand EventName="ShowGridMenu" Command="{Binding ElementName=uc, Path=DataContext.ShowGridMenuCommand}" PassEventArgsToCommand="True"></dxmvvm:EventToCommand>
                                            </dxmvvm:Interaction.Behaviors>
                                            <dxg:TableView.ColumnMenuCustomizations>
                                                <dxb:BarButtonItem Name="ShowColumnChooser" Content="显示列选择" 
                                                                   Command="{Binding ElementName=uc,Path=DataContext.ColumnChoiceCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                            </dxg:TableView.ColumnMenuCustomizations>
                                            <dxg:TableView.RowCellMenuCustomizations>
                                                <dxb:BarButtonItem Name="OpenAndTakePage" Content="Take"
                                                                   Command="{Binding ElementName=uc,Path=DataContext.OpenAndTakePageCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                                <dxb:BarButtonItem Name="OpenAndTakeContinuePage" Content="Continue"
                                                                   Command="{Binding ElementName=uc,Path=DataContext.OpenAndTakeContinueCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                                <dxb:BarButtonItem Name="OpenAndTakeOutPage" Content="TakeOut"
                                                                   Command="{Binding ElementName=uc,Path=DataContext.OpenAndTakeOutCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                                <dxb:BarItemLinkSeparator />
                                                <dxb:BarButtonItem Name="OpenPage" Content="打开" 
                                                                   Command="{Binding ElementName=uc,Path=DataContext.OpenPageCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                                <dxb:BarItemLinkSeparator />
                                                <dxb:BarButtonItem Name="CreateCmdPage" Content="添加命令页" 
                                                                   Command="{Binding ElementName=uc,Path=DataContext.CreateCmdPageCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                                <dxb:BarItemLinkSeparator />
                                                <dxb:BarButtonItem Name="Update" Content="更新选中页" 
                                                                   Command="{Binding ElementName=uc,Path=DataContext.UpdateCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                                <dxb:BarButtonItem Name="TakeInit" Content="初始化选中页" 
                                                                   Command="{Binding ElementName=uc,Path=DataContext.TakeInitCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                                <dxb:BarItemLinkSeparator />
                                                <dxb:BarButtonItem Name="CopyPage" Content="复制选中页 ( Ctrl + C )" 
                                                                   Command="{Binding ElementName=uc,Path=DataContext.BeginCopyPageCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                                <dxb:BarButtonItem Name="PastePage" Content="粘贴页 ( Ctrl + V )" 
                                                                   Command="{Binding ElementName=uc,Path=DataContext.PastePageCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>
                                                <dxb:BarItemLinkSeparator />
                                                <dxb:BarButtonItem Name="DeleteItem" Content="删除选中页 ( Delete )" 
                                                                   Command="{Binding ElementName=uc,Path=DataContext.DeleteItemCommand}"
                                                                   Tag="{x:Static Member=common:GridControlHelper.KEEP_MENU_TAG}"/>

                                            </dxg:TableView.RowCellMenuCustomizations>
                                        </dxg:TableView>
                                    </dxg:GridControl.View>
                                </dxg:GridControl>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Header" Value="{Binding GroupName}" />
                    <Setter Property="dx:TabControlStretchView.PinMode" Value="Left" />
                </Style>
            </dx:DXTabControl.ItemContainerStyle>
        </dx:DXTabControl>

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