<UserControl x:Class="VIZ.Package.Module.ConnSettingView"
             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:fcommon="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common"
             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:ConnSettingViewModel}" 
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/VIZ.Framework.Common.Resource;component/Style/GridSplitter/GridSplitter_None.xaml"></ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
            <resource:RowHandleConverter x:Key="RowHandleConverter"></resource:RowHandleConverter>
            <fcore:Bool2StringConverter x:Key="Bool2StringConverter" TrueResult="默认"></fcore:Bool2StringConverter>
        </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="450" MaxWidth="800"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <GroupBox Header="分组" Margin="10,10,5,10" Padding="10">
            <dxg:GridControl ItemsSource="{Binding Path=Groups}" ShowBorder="False"
                             SelectedItem="{Binding Path=SelectedGroup,Mode=TwoWay}">
                <dxg:GridControl.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="添加分组" Command="{Binding Path=PlacementTarget.DataContext.AddGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                        <MenuItem Header="删除分组" Command="{Binding Path=PlacementTarget.DataContext.DeleteGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                        <Separator/>
                        <MenuItem Header="设为默认分组" Command="{Binding Path=PlacementTarget.DataContext.SetDefaultGroupCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    </ContextMenu>
                </dxg:GridControl.ContextMenu>
                <dxg:GridControl.Columns>
                    <dxg:GridColumn Header="序号" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False" Width="40" AllowResizing="False">
                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding RowData.RowHandle,Converter={StaticResource RowHandleConverter}}"></TextBlock>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>
                    <dxg:GridColumn Header="分组名称" FieldName="Name" AllowSorting="False" AllowColumnFiltering="False">
                        <dxg:GridColumn.EditSettings>
                            <dxe:TextEditSettings TextWrapping="Wrap" TextTrimming="CharacterEllipsis" MaxLength="50"
                                              HorizontalContentAlignment="Left"></dxe:TextEditSettings>
                        </dxg:GridColumn.EditSettings>
                    </dxg:GridColumn>
                    <dxg:GridColumn Header="默认分组" Width="80" AllowEditing="False" 
                                    AllowSorting="False" AllowColumnFiltering="False" ReadOnly="True">
                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Margin="4,0,4,0" VerticalAlignment="Center"
                                           Text="{Binding Row.IsDefault,Converter={StaticResource Bool2StringConverter}}"></TextBlock>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>
                    <dxg:GridColumn Header="是否启用" FieldName="IsEnabled" Width="80" AllowSorting="False" AllowColumnFiltering="False">
                        <dxg:GridColumn.EditSettings>
                            <dxe:CheckEditSettings></dxe:CheckEditSettings>
                        </dxg:GridColumn.EditSettings>
                    </dxg:GridColumn>
                    <dxg:GridColumn Header="引擎类型" FieldName="EngineType" AllowSorting="False" AllowColumnFiltering="False"
                                    ReadOnly="True"></dxg:GridColumn>
                </dxg:GridControl.Columns>
                <dxg:GridControl.View>
                    <dxg:TableView AllowEditing="True" ShowIndicator="False"
                                   IsColumnMenuEnabled="False" 
                                   ShowGroupPanelsForUngroupedDetails="False"
                                   NavigationStyle="Cell" ShowVerticalLines="False"
                                   ShowGroupPanel="False"
                                   AllowDragDrop="False"
                                   ShowBandsPanel="False"
                                   ShowTotalSummary="False"
                                   ShowFixedTotalSummary="False"
                                   ShowDragDropHint="False"
                                   ShowTargetInfoInDragDropHint="false">
                    </dxg:TableView>
                </dxg:GridControl.View>
            </dxg:GridControl>
        </GroupBox>

        <GridSplitter HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="5"
                      Style="{StaticResource GridSplitter_None}"></GridSplitter>

        <GroupBox Header="项" Margin="0,10,10,10" Padding="10" Grid.Column="1">
            <dxg:GridControl ItemsSource="{Binding Path=SelectedGroup.Items}" ShowBorder="False" Grid.Column="1"
                         SelectedItem="{Binding Path=SelectedItem,Mode=TwoWay}">
                <dxg:GridControl.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="添加" Command="{Binding Path=PlacementTarget.DataContext.AddItemCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                        <MenuItem Header="删除" Command="{Binding Path=PlacementTarget.DataContext.DeleteItemCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
                    </ContextMenu>
                </dxg:GridControl.ContextMenu>
                <dxg:GridControl.Columns>
                    <dxg:GridColumn Header="序号" ReadOnly="True" AllowSorting="False" AllowColumnFiltering="False" Width="40" AllowResizing="False">
                        <dxg:GridColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding RowData.RowHandle,Converter={StaticResource RowHandleConverter}}"></TextBlock>
                            </DataTemplate>
                        </dxg:GridColumn.CellTemplate>
                    </dxg:GridColumn>
                    <dxg:GridColumn Header="IP地址" FieldName="IP" AllowSorting="False" AllowColumnFiltering="False">
                        <dxg:GridColumn.EditSettings>
                            <dxe:TextEditSettings TextWrapping="Wrap" MaskType="RegEx" HorizontalContentAlignment="Left"
                                                  Mask="(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"></dxe:TextEditSettings>
                        </dxg:GridColumn.EditSettings>
                    </dxg:GridColumn>
                    <dxg:GridColumn Header="端口" FieldName="Port" AllowSorting="False" AllowColumnFiltering="False">
                        <dxg:GridColumn.EditSettings>
                            <dxe:TextEditSettings TextWrapping="Wrap" MaskType="RegEx" HorizontalContentAlignment="Left" MaxLength="7"
                                              Mask="[0-9]*"></dxe:TextEditSettings>
                        </dxg:GridColumn.EditSettings>
                    </dxg:GridColumn>
                    <dxg:GridColumn Header="备注" FieldName="Remark" AllowSorting="False" AllowColumnFiltering="False">
                        <dxg:GridColumn.EditSettings>
                            <dxe:TextEditSettings TextWrapping="Wrap" TextTrimming="CharacterEllipsis" MaxLength="50"
                                              HorizontalContentAlignment="Left"></dxe:TextEditSettings>
                        </dxg:GridColumn.EditSettings>
                    </dxg:GridColumn>
                    <dxg:GridColumn Header="是否启用" Width="80" FieldName="IsEnabled" AllowSorting="False" AllowColumnFiltering="False">
                        <dxg:GridColumn.EditSettings>
                            <dxe:CheckEditSettings></dxe:CheckEditSettings>
                        </dxg:GridColumn.EditSettings>
                    </dxg:GridColumn>
                </dxg:GridControl.Columns>
                <dxg:GridControl.View>
                    <dxg:TableView AllowEditing="True" ShowIndicator="False"
                                   IsColumnMenuEnabled="False"
                                   NavigationStyle="Cell" ShowVerticalLines="False"
                                   ShowGroupPanel="False"
                                   AllowDragDrop="False"
                                   ShowBandsPanel="False"
                                   ShowTotalSummary="False"
                                   ShowFixedTotalSummary="False"
                                   ShowDragDropHint="False"
                                   ShowTargetInfoInDragDropHint="false">
                    </dxg:TableView>
                </dxg:GridControl.View>
            </dxg:GridControl>
        </GroupBox>
    </Grid>
</UserControl>