Wednesday, 20 July 2016

Convert Winforms Image to WPF

  public static BitmapImage ToWpfImage(System.Drawing.Image img)
        {
            MemoryStream ms = new MemoryStream();  // no using here! BitmapImage will dispose the stream after loading
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            BitmapImage ix = new BitmapImage();
            try
            {
               
                ix.BeginInit();
                ix.CacheOption = BitmapCacheOption.OnLoad;
                ix.StreamSource = ms;
                ix.EndInit();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                var methodName = new StackTrace(ex).GetFrame(0).GetMethod().Name;
                Errorlog.Errorlog.WriteToErrorLog(ex.Message, ex.StackTrace, "Error", methodName);
            }
            return ix;

        }

Stop Backgound .exe

protected override void OnExit(ExitEventArgs e)
        {
            try
            {
                //Put your special code here
            }
            finally
            {
                base.OnExit(e);

            }

Splash Screen in WPF



//App.Xaml.cs

            SplashScreen splashScreen = new SplashScreen("Images/SplashLogo.png");          
            splashScreen.Show(true);
            for (int i = 0; i < 1000; i++)
            {
        
                Thread.Sleep(1);
            }       
          
            var app = new App();
            var window = new Home();

            app.Run(window);

Scroll Bar Design in WPF

<SolidColorBrush x:Key="StandardBorderBrush" Color="#888" />
            <SolidColorBrush x:Key="StandardBackgroundBrush" Color="#FFF" />
            <SolidColorBrush x:Key="HoverBorderBrush" Color="#DDD" />
            <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="Gray" />
            <SolidColorBrush x:Key="SelectedForegroundBrush" Color="White" />
            <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
            <SolidColorBrush x:Key="NormalBrush" Color="White" />
            <SolidColorBrush x:Key="NormalBorderBrush" Color="#071c2c" />
            <SolidColorBrush x:Key="HorizontalNormalBrush" Color="#888" />
            <SolidColorBrush x:Key="HorizontalNormalBorderBrush" Color="#888" />
            <LinearGradientBrush x:Key="ListBoxBackgroundBrush"
            StartPoint="0,0" EndPoint="1,0.001">
                <GradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="White" Offset="0.0" />
                        <GradientStop Color="White" Offset="0.6" />
                        <GradientStop Color="#DDDDDD" Offset="1.2"/>
                    </GradientStopCollection>
                </GradientBrush.GradientStops>
            </LinearGradientBrush>
            <LinearGradientBrush x:Key="StandardBrush"
            StartPoint="0,0" EndPoint="0,1">
                <GradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="#FFF" Offset="0.0"/>
                        <GradientStop Color="#CCC" Offset="1.0"/>
                    </GradientStopCollection>
                </GradientBrush.GradientStops>
            </LinearGradientBrush>
            <SolidColorBrush x:Key="GlyphBrush" Color="#444" />
            <LinearGradientBrush x:Key="PressedBrush"
            StartPoint="0,0" EndPoint="0,1">
                <GradientBrush.GradientStops>
                    <GradientStopCollection>
                        <GradientStop Color="#BBB" Offset="0.0"/>
                        <GradientStop Color="#EEE" Offset="0.1"/>
                        <GradientStop Color="#EEE" Offset="0.9"/>
                        <GradientStop Color="#FFF" Offset="1.0"/>
                    </GradientStopCollection>
                </GradientBrush.GradientStops>
            </LinearGradientBrush>

            <!-- SrollViewer ScrollBar Repeat Buttons (at each end) -->
            <Style x:Key="ScrollBarLineButton" TargetType="{x:Type RepeatButton}">
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="OverridesDefaultStyle" Value="true"/>
                <Setter Property="Focusable" Value="false"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type RepeatButton}">
                            <Border
          Name="Border"
          Margin="1"
          CornerRadius="1"
          Background="{StaticResource NormalBrush}"
          BorderBrush="{StaticResource NormalBorderBrush}"
          BorderThickness="1">
                                <Path
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Fill="{StaticResource GlyphBrush}"
            Data="{Binding Path=Content,
                RelativeSource={RelativeSource TemplatedParent}}" />
                            </Border>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsPressed" Value="true">
                                    <Setter TargetName="Border" Property="Background"
                                Value="{StaticResource PressedBrush}" />
                                </Trigger>
                                <Trigger Property="IsEnabled" Value="false">
                                    <Setter Property="Foreground"
                                Value="{StaticResource DisabledForegroundBrush}"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <!-- SrollViewer ScrollBar Repeat Buttons (The part in the middle,
             not the thumb the long area between the buttons ) -->
            <Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="Background" Value="White"/>
                <Setter Property="OverridesDefaultStyle" Value="true"/>
                <Setter Property="IsTabStop" Value="false"/>
                <Setter Property="Focusable" Value="false"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type RepeatButton}">
                            <Border Background="Transparent" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <!-- ScrollViewer ScrollBar Thumb, that part that can be dragged
            up/down or left/right Buttons -->
            <Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="OverridesDefaultStyle" Value="true"/>
                <Setter Property="IsTabStop" Value="false"/>
                <Setter Property="Focusable" Value="false"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Thumb}">
                            <Border
          CornerRadius="2"
          Background="#071c2c"
          BorderBrush="{TemplateBinding BorderBrush}"
          BorderThickness="1" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <ControlTemplate x:Key="VerticalScrollBar"
            TargetType="{x:Type ScrollBar}">
                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition MaxHeight="18"/>
                        <RowDefinition Height="0.00001*"/>
                        <RowDefinition MaxHeight="18"/>
                    </Grid.RowDefinitions>
                    <Border
      Grid.RowSpan="3"
      CornerRadius="1"
      Background="#F0F0F0" />
                    <RepeatButton
      Grid.Row="0"
      Style="{StaticResource ScrollBarLineButton}"
      Height="18"
      Command="ScrollBar.LineUpCommand"
      Content="M 0 4 L 8 4 L 4 0 Z" />
                    <Track
      Name="PART_Track"
      Grid.Row="1"
      IsDirectionReversed="true">
                        <Track.DecreaseRepeatButton>
                            <RepeatButton
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageUpCommand" />
                        </Track.DecreaseRepeatButton>
                        <Track.Thumb>
                            <Thumb
          Style="{StaticResource ScrollBarThumb}"
          Margin="1,0,1,0"
          Background="{StaticResource HorizontalNormalBrush}"
          BorderBrush="{StaticResource HorizontalNormalBorderBrush}" />
                        </Track.Thumb>
                        <Track.IncreaseRepeatButton>
                            <RepeatButton
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageDownCommand" />
                        </Track.IncreaseRepeatButton>
                    </Track>
                    <RepeatButton
      Grid.Row="3"
      Style="{StaticResource ScrollBarLineButton}"
      Height="18"
      Command="ScrollBar.LineDownCommand"
      Content="M 0 0 L 4 4 L 8 0 Z"/>
                </Grid>
            </ControlTemplate>
            <!-- HorizontalScrollBar Template using the previously created Templates -->
            <ControlTemplate x:Key="HorizontalScrollBar"
            TargetType="{x:Type ScrollBar}">
                <Grid >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MaxWidth="18"/>
                        <ColumnDefinition Width="0.00001*"/>
                        <ColumnDefinition MaxWidth="18"/>
                    </Grid.ColumnDefinitions>
                    <Border
      Grid.ColumnSpan="3"
      CornerRadius="2"
      Background="#F0F0F0" />
                    <RepeatButton
      Grid.Column="0"
      Style="{StaticResource ScrollBarLineButton}"
      Width="18"
      Command="ScrollBar.LineLeftCommand"
      Content="M 4 0 L 4 8 L 0 4 Z" />
                    <Track
      Name="PART_Track"
      Grid.Column="1"
      IsDirectionReversed="False">
                        <Track.DecreaseRepeatButton>
                            <RepeatButton
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageLeftCommand" />
                        </Track.DecreaseRepeatButton>
                        <Track.Thumb>
                            <Thumb
          Style="{StaticResource ScrollBarThumb}"
          Margin="0,1,0,1"
          Background="{StaticResource NormalBrush}"
          BorderBrush="{StaticResource NormalBorderBrush}" />
                        </Track.Thumb>
                        <Track.IncreaseRepeatButton>
                            <RepeatButton
          Style="{StaticResource ScrollBarPageButton}"
          Command="ScrollBar.PageRightCommand" />
                        </Track.IncreaseRepeatButton>
                    </Track>
                    <RepeatButton
      Grid.Column="3"
      Style="{StaticResource ScrollBarLineButton}"
      Width="18"
      Command="ScrollBar.LineRightCommand"
      Content="M 0 0 L 4 4 L 0 8 Z"/>
                </Grid>
            </ControlTemplate>
            <!-- Style for overall  ScrollBar -->
            <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
                <Setter Property="SnapsToDevicePixels" Value="True"/>
                <Setter Property="OverridesDefaultStyle" Value="true"/>
                <Style.Triggers>
                    <Trigger Property="Orientation" Value="Horizontal">
                        <Setter Property="Width" Value="Auto"/>
                        <Setter Property="Height" Value="18" />
                        <Setter Property="Template"
                        Value="{StaticResource HorizontalScrollBar}" />
                    </Trigger>
                    <Trigger Property="Orientation" Value="Vertical">
                        <Setter Property="Width" Value="18"/>
                        <Setter Property="Height" Value="Auto" />
                        <Setter Property="Template"
                        Value="{StaticResource VerticalScrollBar}" />
                    </Trigger>
                </Style.Triggers>
            </Style>

            <!-- Style for overall  ScrollViewer -->
            <Style x:Key="FavsScrollViewer" TargetType="{x:Type ScrollViewer}">
                <Setter Property="OverridesDefaultStyle" Value="True"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ScrollViewer}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>

                                <ScrollContentPresenter Grid.Column="1"/>

                                <ScrollBar Name="PART_VerticalScrollBar"
            Value="{TemplateBinding VerticalOffset}"
            Maximum="{TemplateBinding ScrollableHeight}"
            ViewportSize="{TemplateBinding ViewportHeight}"
            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                                <ScrollBar Name="PART_HorizontalScrollBar"
            Orientation="Horizontal"
            Grid.Row="1"
            Grid.Column="1"
            Value="{TemplateBinding HorizontalOffset}"
            Maximum="{TemplateBinding ScrollableWidth}"
            ViewportSize="{TemplateBinding ViewportWidth}"
            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>

                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
            <Style x:Key="DataGrid_Centering"
        TargetType="{x:Type DataGridCell}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type DataGridCell}">
                            <Grid Background="{TemplateBinding Background}">
                                <ContentPresenter VerticalAlignment="Center" />
                                <ContentPresenter HorizontalAlignment="Center" />
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="Height" Value="30"></Setter>
            </Style>


ProgressBar color change in WPF

<Style x:Key="{x:Type ProgressBar}"
       TargetType="{x:Type ProgressBar}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ProgressBar}">
                        <Grid MinHeight="14"
              MinWidth="200"
              Background="{TemplateBinding Background}" >
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Determinate" />
                                    <VisualState x:Name="Indeterminate">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Duration="00:00:00"
                                                 Storyboard.TargetName="PART_Indicator"
                                                 Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <SolidColorBrush>Transparent</SolidColorBrush>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>

                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Border x:Name="PART_Track"
                  CornerRadius="2"
                  BorderThickness="1" BorderBrush="Black">
                                <!--<Border.BorderBrush>
                                    <SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
                                </Border.BorderBrush>-->
                            </Border>
                            <Border x:Name="PART_Indicator"     CornerRadius="2"   HorizontalAlignment="Left"  Background="{TemplateBinding Foreground}"   BorderBrush="Black">
                                <!--<Border.BorderBrush>
                                    <LinearGradientBrush StartPoint="0,0"       EndPoint="0,1">
                                        <GradientBrush.GradientStops>
                                            <GradientStopCollection>
                                                <GradientStop Color="{DynamicResource BorderLightColor}"
                                  Offset="0.0" />
                                                <GradientStop Color="{DynamicResource BorderMediumColor}"
                                  Offset="1.0" />
                                            </GradientStopCollection>
                                        </GradientBrush.GradientStops>
                                    </LinearGradientBrush>

                                </Border.BorderBrush>
                                <Grid ClipToBounds="True"
                  x:Name="Animation">
                                    <Rectangle x:Name="PART_GlowRect"
                         Width="100"
                         HorizontalAlignment="Left"
                         Fill="{StaticResource ProgressBarIndicatorAnimatedFill}"
                         Margin="-100,0,0,0" />
                                </Grid>-->
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Background" Value="White">
                <!--<Setter.Value>
                    <LinearGradientBrush EndPoint="0,1"
                           StartPoint="0,0">
                        <GradientStop Color="{DynamicResource ControlLightColor}"
                      Offset="0" />
                        <GradientStop Color="{DynamicResource ControlMediumColor}"
                      Offset="1" />
                    </LinearGradientBrush>
                </Setter.Value>-->
            </Setter>
            <Setter Property="Foreground" Value="#e15413">
                <!--<Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1"
                           StartPoint="0.5,0">
                        <GradientStop Color="{DynamicResource ControlMediumColor}"
                      Offset="0" />
                        <GradientStop Color="{DynamicResource ControlDarkColor}"
                      Offset="1" />
                    </LinearGradientBrush>
                </Setter.Value>-->
            </Setter>
        </Style>

Custom Keyboard in WPF


XAML:


<Style x:Key="KeyBoardButton" TargetType="Button">
            <Setter Property="FontFamily" Value="Arial-BoldMT"></Setter>
            <Setter Property="FontSize" Value="36"></Setter>
            <Setter Property="Foreground" Value="#071c2c"></Setter>
            <Setter Property="BorderBrush" Value="#071c2c"></Setter>
            <Setter Property="BorderThickness" Value="2"></Setter>
            <Setter Property="Background" Value="#dde1e9"></Setter>
            <Setter Property="Width" Value="85"></Setter>
            <Setter Property="Height" Value="75"></Setter>
            <Setter Property="HorizontalAlignment" Value="Center"></Setter>
            <Setter Property="VerticalAlignment" Value="Center"></Setter>
        </Style>

   <Popup Name="PopUpKeyBoard" Placement="Absolute"  Height="410" Width="270"  HorizontalOffset="490" VerticalOffset="145">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="1*"></RowDefinition>
                        <RowDefinition Height="1*"></RowDefinition>
                        <RowDefinition Height="1*"></RowDefinition>
                        <RowDefinition Height="1*"></RowDefinition>
                        <RowDefinition Height="1*"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*"></ColumnDefinition>
                        <ColumnDefinition Width="1*"></ColumnDefinition>
                        <ColumnDefinition Width="1*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>

                    <Button x:Name="Closeboard" Grid.Row="0" Grid.Column="2" Content="X" Style="{StaticResource KeyBoardButton}" CommandParameter="CLOSE" Click="KeyPadButton_Click" ></Button>
                    <Button x:Name="one" Grid.Row="1" Grid.Column="0" Content="1" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD1"  Click="KeyPadButton_Click"></Button>
                    <Button x:Name="two" Grid.Row="1" Grid.Column="1" Content="2" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD2"  Click="KeyPadButton_Click"></Button>
                    <Button x:Name="three" Grid.Row="1" Grid.Column="2" Content="3" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD3"  Click="KeyPadButton_Click"></Button>
                    <Button x:Name="four" Grid.Row="2" Grid.Column="0" Content="4" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD4"  Click="KeyPadButton_Click"></Button>
                    <Button x:Name="five" Grid.Row="2" Grid.Column="1" Content="5" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD5"  Click="KeyPadButton_Click"></Button>
                    <Button x:Name="six" Grid.Row="2" Grid.Column="2" Content="6" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD6"  Click="KeyPadButton_Click"></Button>
                    <Button x:Name="seven" Grid.Row="3" Grid.Column="0" Content="7" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD7"  Click="KeyPadButton_Click"></Button>
                    <Button x:Name="eight" Grid.Row="3" Grid.Column="1" Content="8" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD8" Click="KeyPadButton_Click"></Button>
                    <Button x:Name="nine" Grid.Row="3" Grid.Column="2" Content="9" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD9" Click="KeyPadButton_Click"></Button>
                    <Button x:Name="zero" Grid.Row="4" Grid.Column="1" Content="0" Style="{StaticResource KeyBoardButton}" CommandParameter="NUMPAD0" Click="KeyPadButton_Click"></Button>
                    <Button x:Name="back" Grid.Row="4" Grid.Column="2" Style="{StaticResource KeyBoardButton}" CommandParameter="BACK" Click="KeyPadButton_Click">
                        <Image Source="..\Images\icn-backarrow@3x.png" Width="40"></Image>
                    </Button>
                </Grid>
            </Popup>



CS Code:

  private TextBox SelectedTextBox;
        private bool GotFocusTextbox=false;


private void OpenKeyboard(TextBox txtBox)
        {
            try
            {
                ostk.CloseKeyboard();
                PopUpKeyBoard.IsOpen = true;
                SelectedTextBox = txtBox;
                GotFocusTextbox = true;
            }
            catch (Exception ex)
            {
                var methodName = new StackTrace(ex).GetFrame(0).GetMethod().Name;
                Errorlog.Errorlog.WriteToErrorLog(ex.Message, ex.StackTrace, "Error", methodName);
            }
        }

     

        private void CloseKeyboard()
        {
            try
            {
                PopUpKeyBoard.IsOpen = false;
                GotFocusTextbox = false;
                SelectedTextBox = null;
            }
            catch (Exception ex)
            {
                var methodName = new StackTrace(ex).GetFrame(0).GetMethod().Name;
                Errorlog.Errorlog.WriteToErrorLog(ex.Message, ex.StackTrace, "Error", methodName);
            }
        }

private void Textbox_GotFocus(object sender, RoutedEventArgs e)
        {        
            OpenKeyboard(sender as TextBox); //Open a keyboard
        }

  private void KeyPadButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Button button = sender as Button;

                switch (button.CommandParameter.ToString())
                {

                    case "CLOSE":
                        CloseKeyboard();
                        break;

                    case "BACK":
                        if (SelectedTextBox.Text.Length > 0)
                            SelectedTextBox.Text = SelectedTextBox.Text.Remove(SelectedTextBox.Text.Length - 1);
                        break;

                    default:
                        if (SelectedTextBox != null)
                        {
                            if (GotFocusTextbox)
                            {
                                SelectedTextBox.Text = "";
                                SelectedTextBox.Text += button.Content.ToString();
                            }
                            else
                            {
                                SelectedTextBox.Text += button.Content.ToString();
                            }
                        }
                        GotFocusTextbox = false;
                        break;
                }
            }
            catch (Exception ex)
            {
                var methodName = new StackTrace(ex).GetFrame(0).GetMethod().Name;
                Errorlog.Errorlog.WriteToErrorLog(ex.Message, ex.StackTrace, "Error", methodName);
            }
        }


Drop Down Style in WPF

<SolidColorBrush x:Key="ComboBoxNormalBorderBrush" Color="#071c2c" />
    <SolidColorBrush x:Key="ComboBoxNormalBackgroundBrush" Color="#fff" />
    <SolidColorBrush x:Key="ComboBoxNormalBackgroundBrushArrow" Color="#071c2c" />
    <SolidColorBrush x:Key="ComboBoxDisabledForegroundBrush" Color="#888" />
    <SolidColorBrush x:Key="ComboBoxDisabledBackgroundBrush" Color="#eee" />
    <SolidColorBrush x:Key="ComboBoxDisabledBorderBrush" Color="#888" />

    <ControlTemplate TargetType="ToggleButton" x:Key="ComboBoxToggleButtonTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="26" />
            </Grid.ColumnDefinitions>
            <Border Grid.ColumnSpan="2" Name="Border"
              BorderBrush="{StaticResource ComboBoxNormalBorderBrush}"
              CornerRadius="0" BorderThickness="1, 1, 1, 1"
              Background="{StaticResource ComboBoxNormalBackgroundBrush}" />
            <Border Grid.Column="1" Margin="1, 1, 1, 1" BorderBrush="#444" Name="ButtonBorder"
              CornerRadius="0, 0, 0, 0" BorderThickness="0, 0, 0, 0"
              Background="{StaticResource ComboBoxNormalBackgroundBrushArrow}" />

            <Path Name="Arrow" Grid.Column="1"
            Data="M0,0 L0,2 L4,6 L8,2 L8,0 L4,4 z"
            HorizontalAlignment="Center" Fill="White"
            VerticalAlignment="Center" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="UIElement.IsMouseOver" Value="True">
                <Setter Property="Panel.Background" TargetName="ButtonBorder" Value="White"/>
                <Setter Property="Shape.Fill" TargetName="Arrow" Value="#071c2c"/>
             
            </Trigger>
            <Trigger Property="ToggleButton.IsChecked" Value="True">
                <Setter Property="Panel.Background" TargetName="ButtonBorder" Value="#071c2c"/>
                <Setter Property="Shape.Fill" TargetName="Arrow" Value="White"/>
            </Trigger>
            <Trigger Property="UIElement.IsEnabled" Value="False">
                <Setter Property="Panel.Background" TargetName="Border" Value="{StaticResource ComboBoxDisabledBackgroundBrush}"/>
                <Setter Property="Panel.Background" TargetName="ButtonBorder" Value="{StaticResource ComboBoxDisabledBackgroundBrush}"/>
                <Setter Property="Border.BorderBrush" TargetName="ButtonBorder" Value="{StaticResource ComboBoxDisabledBorderBrush}"/>
                <Setter Property="TextElement.Foreground" Value="{StaticResource ComboBoxDisabledForegroundBrush}"/>
                <Setter Property="Shape.Fill" TargetName="Arrow" Value="#999"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style  TargetType="{x:Type ComboBox}">
        <Setter Property="UIElement.SnapsToDevicePixels" Value="True"/>
        <Setter Property="FrameworkElement.OverridesDefaultStyle" Value="True"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
        <Setter Property="TextElement.Foreground" Value="#071c2c"/>
        <Setter Property="FrameworkElement.FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="FontFamily" Value="Arial-BoldMT"></Setter>
        <Setter Property="FontSize" Value="30"></Setter>
        <Setter Property="FontWeight" Value="SemiBold"></Setter>
    
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="ComboBox">
                    <Grid>
                        <ToggleButton Name="ToggleButton" Grid.Column="2"
                ClickMode="Press" Focusable="False"
                IsChecked="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
                Template="{StaticResource ComboBoxToggleButtonTemplate}"/>

                        <ContentPresenter Name="ContentSite" Margin="5, 3, 23, 3" IsHitTestVisible="False"
                              HorizontalAlignment="Left" VerticalAlignment="Center"                             
                              Content="{TemplateBinding ComboBox.SelectionBoxItem}"
                              ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
                              ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"/>
                       
                        <TextBox Name="PART_EditableTextBox" Margin="3, 3, 23, 3"                    
                     IsReadOnly="{TemplateBinding IsReadOnly}"
                     Visibility="Hidden" Background="Transparent"
                     HorizontalAlignment="Left" VerticalAlignment="Center"
                     Focusable="True" >
                            <TextBox.Template>
                                <ControlTemplate TargetType="TextBox" >
                                    <Border Name="PART_ContentHost" Focusable="False" />
                                </ControlTemplate>
                            </TextBox.Template>
                        </TextBox>
                        <!-- Popup showing items -->
                        <Popup Name="Popup" Placement="Bottom"
                   Focusable="False" AllowsTransparency="True"
                   IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}"
                   PopupAnimation="Slide">
                            <Grid Name="DropDown" SnapsToDevicePixels="True"
                    MinWidth="{TemplateBinding FrameworkElement.ActualWidth}"
                    MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}">
                                <Border Name="DropDownBorder" Background="White" Margin="0, 1, 0, 0"
                        CornerRadius="0" BorderThickness="1,1,1,1"
                        BorderBrush="{StaticResource ComboBoxNormalBorderBrush}"/>
                                <ScrollViewer Margin="4" SnapsToDevicePixels="True">
                                    <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" />
                                </ScrollViewer>
                            </Grid>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ItemsControl.HasItems" Value="False">
                            <Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder" Value="95"/>
                        </Trigger>
                        <Trigger Property="UIElement.IsEnabled" Value="False">
                            <Setter Property="TextElement.Foreground" Value="{StaticResource ComboBoxDisabledForegroundBrush}"/>
                        </Trigger>
                        <Trigger Property="ItemsControl.IsGrouping" Value="True">
                            <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
                        </Trigger>
                        <Trigger Property="ComboBox.IsEditable" Value="True">
                            <Setter Property="KeyboardNavigation.IsTabStop" Value="False"/>
                            <Setter Property="UIElement.Visibility" TargetName="PART_EditableTextBox" Value="Visible"/>
                            <Setter Property="UIElement.Visibility" TargetName="ContentSite" Value="Hidden"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- End of Flat ComboBox -->