<UserControl x:Class="VIZ.Package.Module.ColorEditPanel"
             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:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
             mc:Ignorable="d"
             x:Name="colorEditControl"
             d:DesignHeight="300" d:DesignWidth="400">

    <UserControl.Resources>
        <dx:ColorToBrushConverter x:Key="ColorToBrushConverter" />
        <Style x:Key="paletteColorsStyle" TargetType="ListBox">
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Background" Value="{x:Null}" />
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Margin" Value="1,0,1,0" />
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Rectangle Fill="{Binding Converter={StaticResource ColorToBrushConverter}}" Width="12" Height="12" Stroke="Gray" StrokeThickness="1" />
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
       
        <ControlTemplate TargetType="RadioButton" x:Key="radioToggle">
            <ToggleButton Content="{TemplateBinding Content}" IsChecked="{Binding IsChecked, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" />
        </ControlTemplate>
        <DataTemplate x:Key="itemTemplate">
            <StackPanel Orientation="Horizontal" Margin="0,1,0,1">
                <ListBox ItemsSource="{Binding Converter={StaticResource PaletteCollectionConverter}}" Margin="6,0,0,0" Style="{StaticResource paletteColorsStyle}"/>
                <TextBlock Text="{Binding Name}" Margin="6,0,6,0"/>
            </StackPanel>
        </DataTemplate>
        <DataTemplate x:Key="smallItemTemplate">
            <StackPanel Orientation="Horizontal" Margin="0,1,0,1">
                <TextBlock Text="{Binding Name}" Margin="6,0,6,0"/>
            </StackPanel>
        </DataTemplate>

        <Style x:Key="ButtonInfoColor" TargetType="dxe:ButtonInfo">
            <Style.Triggers>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Background" Value="White" />
                    <Setter Property="Foreground" Value="Black"/>
                </Trigger>

                <Trigger Property="IsEnabled" Value="True">
                    <Setter Property="Background" Value="Black"/>
                    <Setter Property="Foreground" Value="White"/>
                </Trigger>
                
             </Style.Triggers>
            
        </Style>
    </UserControl.Resources>

    <Grid VerticalAlignment="Top">
        <Grid.RowDefinitions>
            <RowDefinition Height="40"/>
            <RowDefinition Height="40"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <WrapPanel Grid.Row="0"  Height="40">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <!--<ColumnDefinition Width="85"/>
                    <ColumnDefinition Width="85"/>
                    <ColumnDefinition Width="85"/>
                    <ColumnDefinition Width="85"/>-->
                    <ColumnDefinition Width="340"/>
                    <ColumnDefinition Width="60"/>
                </Grid.ColumnDefinitions>
                <dxe:ButtonEdit  ShowText="False" AllowDefaultButton="False" IsEnabled="{Binding BtnGroupEnable,Mode=TwoWay}"  >

                    <dxe:ButtonInfo  Style="{StaticResource ButtonInfoColor }" Content="Ambient"  IsEnabled="{Binding Path=IsEnabledA,Mode=TwoWay}"  Command="{Binding AmbCommand}" Margin="1"/>
                    <dxe:ButtonInfo  Style="{StaticResource ButtonInfoColor }" Content="Diffuse" IsEnabled="{Binding Path=IsEnabledD,Mode=TwoWay}"  Command="{Binding DiffCommand}" Margin="1"/>
                    <dxe:ButtonInfo  Style="{StaticResource ButtonInfoColor }"  Content="Specular" IsEnabled="{Binding Path=IsEnabledS,Mode=TwoWay}"  Command="{Binding SpecCommand}" Margin="1"/>
                    <dxe:ButtonInfo  Style="{StaticResource ButtonInfoColor }"  Content="Emission" IsEnabled="{Binding Path=IsEnabledE,Mode=TwoWay}"  Command="{Binding EmisCommand}" Margin="1"/>


                    <!--<dxe:ButtonInfo   Content="Ambient"  IsEnabled="{Binding Path=IsEnabledA,Mode=TwoWay}"  Command="{Binding AmbCommand}"/>
                    <dxe:ButtonInfo   Content="Diffuse" IsEnabled="{Binding Path=IsEnabledD,Mode=TwoWay}"  Command="{Binding DiffCommand}"/>
                    <dxe:ButtonInfo   Content="Specular" IsEnabled="{Binding Path=IsEnabledS,Mode=TwoWay}"  Command="{Binding SpecCommand}"/>
                    <dxe:ButtonInfo   Content="Emission" IsEnabled="{Binding Path=IsEnabledE,Mode=TwoWay}"  Command="{Binding EmisCommand}"/>-->

                </dxe:ButtonEdit>

                <CheckBox Content="启用"  Margin="10,0,0,0"
                          ToolTip="Title Safe"
                          IsChecked="{Binding Path=IsEnabledAll,Mode=TwoWay}" Grid.Column="4">
                </CheckBox>

                <!--<Button Content="E" Grid.Column="4"  IsEnabled="{Binding Path=IsEnabledAll,Mode=TwoWay}"   Command="{Binding EnableCommand}"  Style="{StaticResource CheckBox_Preview_TA}"/>-->


                <!--<dxe:ToggleSwitch x:Name="toggleSwitch"
                              VerticalAlignment="Center"
                              HorizontalAlignment="Center"
                              CheckedStateContent="E"
                              UncheckedStateContent="E"  
                              ContentPlacement="Inside" 
                               Grid.Column="4"/>-->

            </Grid>

        </WrapPanel>

        <WrapPanel Grid.Row="1"  Height="40">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="40"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="140"/>
                    <ColumnDefinition Width="140"/>
                    <ColumnDefinition Width="120"/>
                    <ColumnDefinition Width="0"/>
                </Grid.ColumnDefinitions>

                <WrapPanel Grid.Column="0" Height="40">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="40"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="60"/>
                            <ColumnDefinition Width="80"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Text="Shininess" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                        <dxe:TextEdit Grid.Column="1" 
                                      Text="{Binding Path=Shininess,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                      HorizontalAlignment="Left" Height="30" Width="80"
                                      Mask="[0-9]\d?|100"  MaskType="RegEx"   MaskUseAsDisplayFormat="True" ShowError="False"
                                      VerticalAlignment="Center"/>

                    </Grid>
                </WrapPanel>

                <WrapPanel Grid.Column="1" Height="40">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="40"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="60"/>
                            <ColumnDefinition Width="80"/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" Text="Alpha" VerticalAlignment="Center" HorizontalAlignment="Center"/>

                        <dxe:TextEdit  Grid.Column="1" Text="{Binding Path=Alpha,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Width="80" Height="30"  ShowError="False"
                                       VerticalAlignment="Center"  Mask="[0-9]\d?|100"  MaskType="RegEx"
                                       MaskUseAsDisplayFormat="True"/>
                        
                    </Grid>
                </WrapPanel>

                <!--<Border Name="currentColor" BorderBrush="DarkGray"  BorderThickness="1" Width="40" Background="{Binding Path=ColorValue, Converter={StaticResource ColorToBrushConverter} }" Grid.Column="2"/>-->

                <dxe:PopupColorEdit Grid.Row="1" Grid.Column="2" x:Name="brushColorEdit" VerticalAlignment="Center"  Height="30" HorizontalAlignment="Center"
                                    Color="{Binding Path=ColorValue,Mode=TwoWay}"   Palettes="{Binding ElementName=palettes, Path=EditValue, Mode=TwoWay}"
                                    ShowDefaultColorButton="False" />


            </Grid>
            
        </WrapPanel>

        <!--<StackPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">

            <dxe:ColorEdit  Color="{Binding Path=ColorValue,Mode=TwoWay}"  ShowDefaultColorButton="False" >
                
            </dxe:ColorEdit>
        </StackPanel>-->
    </Grid>
</UserControl>
