<UserControl x:Class="VIZ.Package.Module.ScrollElementsEditPanel"
             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: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"
             d:DataContext="{d:DesignInstance Type=local:ScrollElementsEditPanelModel}" 
             d:Background="White"
             mc:Ignorable="d"
             d:DesignHeight="400" d:DesignWidth="800">
    <UserControl.Resources>

        <!-- 行号转化器 -->
        <resource:RowHandleConverter x:Key="RowHandleConverter"></resource:RowHandleConverter>
        <!-- 富文本转文本 -->
        <resource:RichText2TextConverter x:Key="RichText2TextConverter"></resource:RichText2TextConverter>

        <!-- 单元格编辑模板选择器 -->
        <local:ScrollElementEditPanelCellTemplateSelector x:Key="CellTemplateSelector">
            <!-- 索引 -->
            <local:ScrollElementEditPanelCellTemplateSelector.IndexTemplate>
                <DataTemplate>
                    <TextBlock Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding RowData.RowHandle,Converter={StaticResource RowHandleConverter}}"></TextBlock>
                </DataTemplate>
            </local:ScrollElementEditPanelCellTemplateSelector.IndexTemplate>
            <!-- 富文本 -->
            <local:ScrollElementEditPanelCellTemplateSelector.RichTextDataTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Value,Converter={StaticResource RichText2TextConverter},Mode=OneWay}" Margin="3,0,3,0"
                               TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" VerticalAlignment="Center"></TextBlock>
                </DataTemplate>
            </local:ScrollElementEditPanelCellTemplateSelector.RichTextDataTemplate>
            <!-- 图片 -->
            <local:ScrollElementEditPanelCellTemplateSelector.ImageDataTemplate>
                <DataTemplate>
                    <local:ImageListCellEdit></local:ImageListCellEdit>
                </DataTemplate>
            </local:ScrollElementEditPanelCellTemplateSelector.ImageDataTemplate>
        </local:ScrollElementEditPanelCellTemplateSelector>

        <!-- 单元格编辑模板选择器 -->
        <local:ScrollElementEditPanelCellTemplateSelector x:Key="CellEditTemplateSelector">
            <!-- 文本 -->
            <local:ScrollElementEditPanelCellTemplateSelector.TextDataTemplate>
                <DataTemplate>
                    <local:TextListCellEdit></local:TextListCellEdit>
                </DataTemplate>
            </local:ScrollElementEditPanelCellTemplateSelector.TextDataTemplate>
            <!-- 富文本 -->
            <local:ScrollElementEditPanelCellTemplateSelector.RichTextDataTemplate>
                <DataTemplate>
                    <local:RichTextScrollElementCellEdit></local:RichTextScrollElementCellEdit>
                </DataTemplate>
            </local:ScrollElementEditPanelCellTemplateSelector.RichTextDataTemplate>
        </local:ScrollElementEditPanelCellTemplateSelector>

        <!-- 列定义模板 -->
        <DataTemplate x:Key="ColumnTemplate">
            <ContentControl>
                <dxg:GridColumn FieldName="{Binding FieldName}"
                                Header="{Binding Header}" ReadOnly="{Binding ReadOnly}"
                                Width="{Binding Width}" MinWidth="{Binding MinWidth}" MaxWidth="{Binding MaxWidth}"
                                CellTemplateSelector="{StaticResource CellTemplateSelector}"
                                CellEditTemplateSelector="{StaticResource CellEditTemplateSelector}"
                                AllowEditing="{Binding AllowEditing}"  
                                AllowResizing="True"
                                AllowSorting="False" AllowColumnFiltering="False"/>
            </ContentControl>
        </DataTemplate>

    </UserControl.Resources>

    <Grid VerticalAlignment="Stretch" AllowDrop="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="40"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="50"></RowDefinition>
        </Grid.RowDefinitions>

        <!-- 模板 -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="60"></ColumnDefinition>
                <ColumnDefinition Width="300"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Text="底飞模板:" VerticalAlignment="Center" HorizontalAlignment="Right" Opacity="0.75"></TextBlock>
            <dxe:ComboBoxEdit IsTextEditable="False" Height="30" Grid.Column="1" Margin="20,0,0,0"
                              EditValue="{Binding Path=SelectedSceneTemplateModel,Mode=TwoWay}"
                              ItemsSource="{Binding Path=SceneTemplateModels,Mode=OneWay}" DisplayMember="Scene"></dxe:ComboBoxEdit>
            <StackPanel Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="40,0,0,0">
                <Button Width="120" Height="30" Content="应用模板" Command="{Binding Path=ApplyTemplateCommand}"></Button>
            </StackPanel>
        </Grid>

        <!-- 数据 -->
        <dxg:GridControl ItemsSource="{Binding Path=ItemsSource}" ShowBorder="True" Grid.Row="1" AllowDrop="True"
                         ColumnsSource="{Binding Path=Columns}" SelectionMode="Row" Margin="10"
                         SelectedItem="{Binding Path=SelectedValue}"
                         SelectedItems="{Binding Path=SelectedValues}"
                         ColumnGeneratorTemplate="{StaticResource ColumnTemplate}">
            <dxg:GridControl.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="添加" Command="{Binding Path=PlacementTarget.DataContext.AddCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    <MenuItem Header="删除" Command="{Binding Path=PlacementTarget.DataContext.RemoveCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                </ContextMenu>
            </dxg:GridControl.ContextMenu>
            <dxg:GridControl.View>
                <dxg:TableView x:Name="tabView" AllowEditing="True" ShowIndicator="False"
                               IsColumnMenuEnabled="False"
                               NavigationStyle="Cell" EditorShowMode="MouseDown" ShowVerticalLines="True"
                               ShowHorizontalLines="True"
                               AlternateRowBackground="#05ffffff"
                               ShowGroupPanel="False" RowMinHeight="24"
                               AllowDrop="True"
                               ShowBandsPanel="False"
                               ShowTotalSummary="False"
                               ShowFixedTotalSummary="False"
                               ShowDragDropHint="False"
                               ShowTargetInfoInDragDropHint="false">
                </dxg:TableView>
            </dxg:GridControl.View>
        </dxg:GridControl>

        <!-- 预览控制 -->
        <Grid Grid.Row="2" Margin="2,0,2,10">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
                <ColumnDefinition Width="80"></ColumnDefinition>
                <ColumnDefinition Width="120"></ColumnDefinition>
                <ColumnDefinition Width="100"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Button Width="80" Height="24" Content="Play" Command="{Binding Path=PreviewPlayCommand}"></Button>
            <Button Width="80" Height="24" Content="Stop" Grid.Column="1" Command="{Binding Path=PreviewStopCommand}"></Button>
            <Button Width="80" Height="24" Content="Continue" Grid.Column="2" Command="{Binding Path=PreviewContinueCommnad}"></Button>
            <TextBlock Text="Position:" Opacity="0.75" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,5,0"></TextBlock>
            <dxe:TextEdit Width="100" Height="24" Grid.Column="4" EditValue="{Binding Path=PreviewPosition,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                          dxe:NumericMaskOptions.ValueAfterDelete="ZeroThenNull"
                          dxe:NumericMaskOptions.AlwaysShowDecimalSeparator="False"
                          MaskType="Numeric" Mask="##########.###"></dxe:TextEdit>
            <Button Width="80" Height="24" Content="Apply" Grid.Column="5" Command="{Binding Path=PreviewSetPosCommand}"></Button>

        </Grid>
    </Grid>
</UserControl>
