<UserControl x:Class="VIZ.Package.Module.ListEditPanel"
             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:Background="White"
             d:DataContext="{d:DesignInstance Type=local:ListEditPanelModel}" 
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <!-- 行号转化器 -->
            <resource:RowHandleConverter x:Key="RowHandleConverter"></resource:RowHandleConverter>
            <!-- 富文本转文本 -->
            <resource:RichText2TextConverter x:Key="RichText2TextConverter"></resource:RichText2TextConverter>

            <!-- 单元格编辑模板选择器 -->
            <local:ListEditPanelCellTemplateSelector x:Key="CellTemplateSelector">
                <!-- 富文本 -->
                <local:ListEditPanelCellTemplateSelector.RichTextDataTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Value,Converter={StaticResource RichText2TextConverter},Mode=OneWay}"
                                   TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" VerticalAlignment="Center"></TextBlock>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.RichTextDataTemplate>
                <!-- Boolean -->
                <local:ListEditPanelCellTemplateSelector.BooleanDataTemplate>
                    <DataTemplate>
                        <local:BooleanListCellEdit></local:BooleanListCellEdit>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.BooleanDataTemplate>
                <!-- 二元值 -->
                <local:ListEditPanelCellTemplateSelector.DupletDataTemplate>
                    <DataTemplate>
                        <local:DupletListCellEdit></local:DupletListCellEdit>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.DupletDataTemplate>
                <!-- 三元值 -->
                <local:ListEditPanelCellTemplateSelector.TripletDataTemplate>
                    <DataTemplate>
                        <local:TripletListCellEdit></local:TripletListCellEdit>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.TripletDataTemplate>
                <!-- 图片 -->
                <local:ListEditPanelCellTemplateSelector.ImageDataTemplate>
                    <DataTemplate>
                        <local:ImageListCellEdit></local:ImageListCellEdit>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.ImageDataTemplate>
                <!-- 字体 -->
                <local:ListEditPanelCellTemplateSelector.FontDataTemplate>
                    <DataTemplate>
                        <local:FontListCellEdit></local:FontListCellEdit>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.FontDataTemplate>
            </local:ListEditPanelCellTemplateSelector>

            <!-- 单元格编辑模板选择器 -->
            <local:ListEditPanelCellTemplateSelector x:Key="CellEditTemplateSelector">
                <!-- 文本 -->
                <local:ListEditPanelCellTemplateSelector.TextDataTemplate>
                    <DataTemplate>
                        <local:TextListCellEdit></local:TextListCellEdit>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.TextDataTemplate>
                <!-- 富文本 -->
                <local:ListEditPanelCellTemplateSelector.RichTextDataTemplate>
                    <DataTemplate>
                        <local:RichTextListCellEdit></local:RichTextListCellEdit>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.RichTextDataTemplate>
                <!-- 数字 -->
                <local:ListEditPanelCellTemplateSelector.IntegerDataTemplate>
                    <DataTemplate>
                        <local:IntegerListCellEdit></local:IntegerListCellEdit>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.IntegerDataTemplate>
                <!-- 浮点数字 -->
                <local:ListEditPanelCellTemplateSelector.FloatDataTemplate>
                    <DataTemplate>
                        <local:FloatListCellEdit></local:FloatListCellEdit>
                    </DataTemplate>
                </local:ListEditPanelCellTemplateSelector.FloatDataTemplate>
            </local:ListEditPanelCellTemplateSelector>

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

    <Grid>
        <dxg:GridControl ItemsSource="{Binding Path=ItemsSource}" ShowBorder="False" Grid.Column="1" AllowDrop="True"
                         ColumnsSource="{Binding Path=Columns}" SelectionMode="Cell"
                         ColumnGeneratorTemplate="{StaticResource ColumnTemplate}">

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

            <dxg:GridControl.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="刷新" Command="{Binding Path=PlacementTarget.DataContext.RefreshControlObjectFieldListCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                </ContextMenu>
            </dxg:GridControl.ContextMenu>
            <dxg:GridControl.View>
                <dxg:TableView x:Name="tabView" AllowEditing="True" ShowIndicator="False" ScrollAnimationMode="EaseInOut" AllowScrollAnimation="True"
                               IsColumnMenuEnabled="False"
                               NavigationStyle="Cell" EditorShowMode="MouseDown" ShowVerticalLines="False"
                               ShowGroupPanel="False"
                               AllowDrop="True"
                               ShowBandsPanel="False"
                               ShowTotalSummary="False"
                               ShowFixedTotalSummary="False"
                               ShowDragDropHint="False"
                               ShowTargetInfoInDragDropHint="false">
                </dxg:TableView>
            </dxg:GridControl.View>
        </dxg:GridControl>
    </Grid>
</UserControl>