<vs:DialogWindow x:Class="Microsoft.Data.Entity.Design.UI.Views.Dialogs.EnumTypeDialog"
                 x:ClassModifier="internal"
                 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:vs="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.12.0"
                 xmlns:ded="clr-namespace:Microsoft.Data.Entity.Design"
                 xmlns:vm="clr-namespace:Microsoft.Data.Entity.Design.UI.ViewModels"
                 xmlns:core-controls="clr-namespace:Microsoft.Data.Entity.Design.Core.Controls;assembly=Microsoft.Data.Tools.Design.XmlCore"
                 mc:Ignorable="d"
                 d:DesignWidth="450" 
                 d:DesignHeight="575"
                 MinWidth="450" 
                 MinHeight="575"
                 SizeToContent="WidthAndHeight"
                 ShowInTaskbar="False"
                 WindowStartupLocation="CenterOwner"
                 ResizeMode="CanResizeWithGrip"
                 FontFamily="{DynamicResource VsFont.EnvironmentFontFamily}"
                 FontSize="{DynamicResource VsFont.EnvironmentFontSize}"
                 BorderBrush="{DynamicResource VsBrush.ActiveBorder}" BorderThickness="0,0,1,0"
                 Background="{DynamicResource {x:Static SystemColors.ControlBrushKey }}"
                 FocusManager.FocusedElement="{Binding ElementName=txtEnumTypeName}">

    <vs:DialogWindow.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Microsoft.Data.Entity.Design;Component/Resources/EscherIcons.xaml"/>
      </ResourceDictionary.MergedDictionaries>

        <!-- Draw hint on top of external type textbox -->
      <VisualBrush x:Key="ExternalTypeHint" TileMode="None" Stretch="None" AlignmentX="Left">
        <VisualBrush.Transform>
          <TranslateTransform X="5" Y="0" />
        </VisualBrush.Transform>
        <VisualBrush.Visual>
          <Grid>
            <TextBlock FontStyle="Italic" Opacity="0.8" Text="{x:Static ded:Resources.EnumDialog_ExternalTypeHint}" />
          </Grid>
        </VisualBrush.Visual>
      </VisualBrush>

      <Style x:Key="ErrorImageStyle" TargetType="{x:Type Image}">
        <Setter Property="AutomationProperties.Name" Value="{x:Static ded:Resources.EnumDialog_Error_AccName}" />
        <Setter Property="Source" Value="{StaticResource WarningPngIcon}" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
        <Setter Property="Stretch" Value="None" />
        <Setter Property="VerticalAlignment" Value="Center" />
      </Style>

      <Style x:Key="BasePopupStyle" TargetType="{x:Type Popup}">
        <Setter Property="AutomationProperties.Name" Value="{x:Static ded:Resources.EnumDialog_Error_AccName}" />
        <Setter Property="Margin" Value="3,3,3,3" />
        <Setter Property="Placement" Value="Bottom" />
        <Setter Property="VerticalOffset" Value="6" />
      </Style>

      <Style x:Key="EnumTypeNamePopupStyle" TargetType="{x:Type Popup}" BasedOn="{StaticResource BasePopupStyle}">
        <Setter Property="PlacementTarget" Value="{Binding ElementName=txtEnumTypeNameWarningImage}" />
        <Style.Triggers>
          <DataTrigger Binding="{Binding ElementName=txtEnumTypeName, Path=(Validation.HasError)}" Value="true" >
            <Setter Property="IsOpen" Value="true"/>
          </DataTrigger>
        </Style.Triggers>
      </Style>

      <Style x:Key="ExternalTypePopupStyle" TargetType="{x:Type Popup}" BasedOn="{StaticResource BasePopupStyle}">
        <Setter Property="PlacementTarget" Value="{Binding ElementName=txtExternalTypeWarningImage}" />
        <Style.Triggers>
          <DataTrigger Binding="{Binding ElementName=txtExternalType, Path=(Validation.HasError)}" Value="true" >
            <Setter Property="IsOpen" Value="true"/>
          </DataTrigger>
        </Style.Triggers>
      </Style>

      <Style x:Key="PopupBorderStyle" TargetType="{x:Type Border}">
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" />
        <Setter Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.InfoTextBrushKey}}" />
      </Style>

      <Style x:Key="PopupTextBlockStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.InfoBrushKey}}" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.InfoTextBrushKey}}" />
        <Setter Property="Margin" Value="4,3,4,3" />
        <Setter Property="VerticalAlignment" Value="Center" />
      </Style>

      <Style TargetType="{x:Type DataGridRow}">
        <Setter Property="ValidationErrorTemplate">
          <Setter.Value>
            <ControlTemplate>
              <DockPanel LastChildFill="True">
                <AdornedElementPlaceholder Name="customAdorner"/>
                <Image Source="{StaticResource WarningPngIcon}" Margin="0,0,0,0" VerticalAlignment="Center"
                       AutomationProperties.Name="WarningError" Stretch="None" ToolTip="{Binding ElementName=customAdorner, 
                                       Path=AdornedElement.(Validation.Errors)[0].ErrorContent}" />
              </DockPanel>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
        <Style.Triggers>
              <Trigger Property="Validation.HasError" Value="true">
                  <Setter Property="Background" Value="{DynamicResource VsBrush.ControlEditRequiredBackground}" />
                  <Setter Property="Foreground" Value="{DynamicResource VsBrush.ControlEditRequiredHintText}" />
                  <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
              </Trigger>
          </Style.Triggers>
      </Style>

      <core-controls:InverseBooleanConverter x:Key="InverseBooleanConverter" />
    </ResourceDictionary>
 </vs:DialogWindow.Resources>
    
    <Grid Margin="10,10,10,10" AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_AutomationName}">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>

      <TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static ded:Resources.EnumDialog_NameLabel}" 
                 VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5,5,5,2"/>

      <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal">
        <TextBox Name="txtEnumTypeName" HorizontalAlignment="Left" 
                 Margin="5,0,5,5" AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_NameLabel}"
                 Width="250px" TextChanged="OnTextBoxTextChanged" LostFocus="OnTextBoxLostFocus" >
          <TextBox.Text>
            <Binding Path="Name">
              <Binding.ValidationRules>
                <vm:CellDataInfoValidationRule ValidationStep="UpdatedValue"/>
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
          <TextBox.Style>
            <Style TargetType="{x:Type TextBox}">
              <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                  <Setter Property="Background" Value="{DynamicResource VsBrush.ControlEditRequiredBackground}" />
                  <Setter Property="Foreground" Value="{DynamicResource VsBrush.ControlEditRequiredHintText}" />
                  <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
              </Style.Triggers>
            </Style>
          </TextBox.Style>
        </TextBox>
        <Image Name="txtEnumTypeNameWarningImage" Margin="3,0,3,5">
          <Image.Style>
            <Style TargetType="{x:Type Image}" BasedOn="{StaticResource ErrorImageStyle}">
              <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=txtEnumTypeName, Path=(Validation.HasError)}" Value="true" >
                  <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding ElementName=txtEnumTypeName, Path=(Validation.HasError)}" Value="false" >
                  <Setter Property="Visibility" Value="Hidden"/>
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </Image.Style>
        </Image>
        <Popup Style="{StaticResource EnumTypeNamePopupStyle}">
          <Border Style="{StaticResource PopupBorderStyle}">
            <TextBlock
                AutomationProperties.Name="{Binding ElementName=txtEnumTypeName, Path=(Validation.Errors)[0].ErrorContent}"
                Style="{StaticResource PopupTextBlockStyle}"
                Text="{Binding ElementName=txtEnumTypeName, Path=(Validation.Errors)[0].ErrorContent}"/>
          </Border>
        </Popup>
      </StackPanel>

      <TextBlock Grid.Column="0" Grid.Row="2" Text="{x:Static ded:Resources.EnumDialog_UnderlyingTypeLabel}" Margin="5,2,5,2" />

      <ComboBox Grid.Column="0" Grid.Row="3"  HorizontalAlignment="Left" Name="cmbUnderlyingType"
                Margin="5,0,5,5" Width="250px"
                ItemsSource="{Binding Path=UnderlyingTypes}"
                SelectedItem="{Binding Path=SelectedUnderlyingType,Mode=TwoWay}"
                AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_UnderlyingTypeLabel}" 
                ToolTip="{x:Static ded:Resources.PropertyWindow_Description_EnumUnderlyingType}"/>

      <DataGrid Grid.Column="0" Grid.Row="4" HorizontalAlignment="Stretch"
                Name="dgEnumTypeMembers" VerticalAlignment="Stretch" ItemsSource="{Binding Path=Members}"
                CanUserAddRows="True" CanUserDeleteRows="True" AutoGenerateColumns="False"
                HorizontalGridLinesBrush="{DynamicResource VsBrush.ThreeDFace}"
                VerticalGridLinesBrush="{DynamicResource VsBrush.ThreeDFace}"
                AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_AccEnumTypeMembers}"
                Margin="5,10,5,5"
                CellEditEnding="dgEnumTypeMembers_CellEditEnding"
                CurrentCellChanged="dgEnumTypeMembers_CurrentCellChanged"
                Loaded="dgEnumTypeMembers_OnLoaded">
        <DataGrid.RowValidationRules>
          <vm:RowDataInfoValidationRule ValidationStep="UpdatedValue" />
        </DataGrid.RowValidationRules>
        <DataGrid.Columns>

          <DataGridTextColumn Header="{x:Static ded:Resources.EnumDialog_EnumTypeMemberNameLabel}"
                              CanUserSort="False" MinWidth="225" MaxWidth="325" Width="Auto"
                              AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_EnumTypeMemberNameLabel}"
                              AutomationProperties.HelpText="{x:Static ded:Resources.EnumDialog_EnumTypeMemberHelpText}">
            <DataGridTextColumn.Binding>
              <Binding Path="Name">
                <Binding.ValidationRules>
                  <vm:CellDataInfoValidationRule ValidationStep="UpdatedValue"/>
                </Binding.ValidationRules>
              </Binding>
            </DataGridTextColumn.Binding>
          </DataGridTextColumn>

                <DataGridTextColumn Header="{x:Static ded:Resources.EnumDialog_EnumTypeMemberValueLabel}"
                                    CanUserSort="False" MinWidth="200" MaxWidth="300" Width="Auto"
                                    AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_EnumTypeMemberValueLabel}"
                                    AutomationProperties.HelpText="{x:Static ded:Resources.EnumDialog_EnumTypeMemberHelpText}">
            <DataGridTextColumn.Binding>
              <Binding Path="Value">
                <Binding.ValidationRules>
                  <vm:CellDataInfoValidationRule ValidationStep="UpdatedValue"/>
                </Binding.ValidationRules>
              </Binding>
            </DataGridTextColumn.Binding>
          </DataGridTextColumn>
        </DataGrid.Columns>
      </DataGrid>

      <CheckBox Content="{x:Static ded:Resources.EnumDialog_IsFlagLabel}" Grid.Column="0" Grid.Row="5"  
                  Name="chkIsFlag" VerticalAlignment="Center" Margin="8,10,5,5" Padding="8,0,5,0" 
                  IsChecked="{Binding Path=IsFlag}" ToolTip="{x:Static ded:Resources.EnumDialog_IsFlagLabelDescription}" />

      <CheckBox Content="{x:Static ded:Resources.EnumDialog_ExternalTypeLabel}" Grid.Column="0" Grid.Row="6"
                Name="chkReferenceExternalType" VerticalAlignment="Center" Margin="8,5,5,2" Padding="8,0,5,0" IsChecked="{Binding Path=IsReferenceExternalType}"
                ToolTip="{x:Static ded:Resources.PropertyWindow_Description_EnumExternalTypeAttribute}" Click="OnRefrenceExternalTypeClick"/>

      <StackPanel Grid.Column="0" Grid.Row="7" Orientation="Horizontal">
        <Border MaxWidth="{Binding ElementName=chkIsFlag,Path=ActualWidth}" Margin="0,0,0,0" BorderThickness="0,0,0,0">
          <TextBox Margin="23,5,5,5" Name="txtExternalType" HorizontalAlignment="Left" AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_ExternalTypeLabel}"
                   Width="230px" IsReadOnly="{Binding Path=IsChecked, ElementName=chkReferenceExternalType, Converter={StaticResource InverseBooleanConverter}}"
                   TextChanged="OnTextBoxTextChanged" LostFocus="OnTextBoxLostFocus">
            <TextBox.Text>
              <Binding Path="ExternalTypeName">
                <Binding.ValidationRules>
                  <vm:CellDataInfoValidationRule ValidationStep="UpdatedValue"/>
                </Binding.ValidationRules>
              </Binding>
            </TextBox.Text>
            <TextBox.Style>
              <Style TargetType="{x:Type TextBox}">
                <Style.Triggers>
                  <MultiTrigger>
                    <MultiTrigger.Conditions>
                      <Condition Property="Text" Value="" />
                      <!-- <Condition Property="IsKeyboardFocusWithin" Value="False"/> -->
                    </MultiTrigger.Conditions>
                    <Setter Property="Background" Value="{StaticResource ExternalTypeHint}"/>
                  </MultiTrigger>
                  <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="Background" Value="{DynamicResource VsBrush.ControlEditRequiredBackground}" />
                    <Setter Property="Foreground" Value="{DynamicResource VsBrush.ControlEditRequiredHintText}" />
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                  </Trigger>
                  <Trigger Property="Visibility" Value="Visible">
                    <Trigger.EnterActions>
                      <BeginStoryboard>
                        <Storyboard>
                          <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                           From="0"
                                           To="1"
                                           Duration="0:0:1" />
                        </Storyboard>
                      </BeginStoryboard>
                    </Trigger.EnterActions>
                  </Trigger>
                </Style.Triggers>
              </Style>
            </TextBox.Style>
          </TextBox>
        </Border>
        <Image Name="txtExternalTypeWarningImage" Margin="3,0,3,2">
          <Image.Style>
            <Style TargetType="{x:Type Image}" BasedOn="{StaticResource ErrorImageStyle}">
              <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=txtExternalType, Path=(Validation.HasError)}" Value="true" >
                  <Setter Property="Visibility" Value="Visible"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding ElementName=txtExternalType, Path=(Validation.HasError)}" Value="false" >
                  <Setter Property="Visibility" Value="Hidden"/>
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </Image.Style>
        </Image>
        <Popup Style="{StaticResource ExternalTypePopupStyle}">
          <Border Style="{StaticResource PopupBorderStyle}">
            <TextBlock
                AutomationProperties.Name="{Binding ElementName=txtExternalType, Path=(Validation.Errors)[0].ErrorContent}"
                Style="{StaticResource PopupTextBlockStyle}"
                Text="{Binding ElementName=txtExternalType, Path=(Validation.Errors)[0].ErrorContent}"/>
          </Border>
        </Popup>
      </StackPanel>

      <StackPanel Grid.Column="0" Grid.Row="8" Orientation="Horizontal" HorizontalAlignment="Right">
         <Button Name="btnOk"
                 Margin="5,15,5,5" MinWidth="70" IsDefault="True" 
                 Click="btnOk_Click" Content="{x:Static ded:Resources.EnumDialog_OkButtonLabel}"
                 IsEnabled="{Binding Path=IsValid}"
                 AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_OkButtonLabel}"/>

        <Button Name="btnCancel" 
                Margin="5,15,5,5" MinWidth="70" IsCancel="True" 
                Click="btnCancel_Click" Content="{x:Static ded:Resources.EnumDialog_CancelButtonLabel}"
                AutomationProperties.Name="{x:Static ded:Resources.EnumDialog_CancelButtonLabel}"/>
      </StackPanel>
  </Grid>
</vs:DialogWindow>