views:

1462

answers:

2

I used XamlPadX to copy the defaultstyle of the ComboBox and pasted it into my app ressources.

Now after that I cannot open the combobox anymore. If I click on the dropdown button, nothing happens.

Another thing is bugging me. Altough the app compiles and runs, the designer shows me an error on the following line:

<ComboBox Name="modifier" SelectedIndex="0" Style="{DynamicResource MyComboStyle}">
       <ComboBoxItem>1</ComboBoxItem>
       <ComboBoxItem>2</ComboBoxItem>
       <ComboBoxItem>3</ComboBoxItem>
</ComboBox>

"Value 'Control.Template' cannot be assigned to property 'Property'. 'IFrameworkInputElement' type does not have a matching DependencyObjectType.".

Because of this the designer doen't show me the control, but it shows up properly when the app is run.

But when I declare the ComboBox as its own control there is no designer error:

Style="{DynamicResource MyComboStyle}" >

Then no designer error is shown.

This is the control template for the combobox which I copied right from XamlPadX (the only modification I made was giving it a name with x:Key="MyComboStyle"):

<Style x:Key="MyComboStyle" TargetType="ComboBox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
    <Style.Triggers>
        <Trigger Property="ComboBox.IsEditable">
            <Setter Property="KeyboardNavigation.IsTabStop">
                <Setter.Value>
                    <s:Boolean>False</s:Boolean>
                </Setter.Value>
            </Setter>
            <Setter Property="Control.Padding">
                <Setter.Value>
                    <Thickness>1,1,1,1</Thickness>
                </Setter.Value>
            </Setter>
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBox">
                        <Border BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
                            <Grid>
                                <mwt:ClassicBorderDecorator Background="{TemplateBinding Panel.Background}" BorderStyle="Sunken" BorderBrush="#00FFFFFF" BorderThickness="2,2,2,2" Name="Border">
                                    <Popup IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" AllowsTransparency="True" Name="PART_Popup" Focusable="False">
                                        <mwt:SystemDropShadowChrome Color="#00FFFFFF" Name="Shdw" MinWidth="30" MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}">
                                            <Border BorderThickness="1,1,1,1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Name="DropDownBorder">
                                                <ScrollViewer>
                                                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained" />
                                                </ScrollViewer>
                                            </Border>
                                        </mwt:SystemDropShadowChrome>
                                    </Popup>
                                </mwt:ClassicBorderDecorator>
                                <ToggleButton IsChecked="False" ClickMode="Press" Width="Auto" MinWidth="0" MinHeight="0" Margin="2,2,2,2" Focusable="False">
                                    <ToggleButton.Style>
                                        <Style TargetType="ToggleButton">
                                            <Style.Triggers>
                                                <Trigger Property="UIElement.IsEnabled">
                                                    <Setter Property="TextElement.Foreground">
                                                        <Setter.Value>
                                                            <DynamicResource ResourceKey="{x:Static SystemColors.ControlDarkBrushKey}" />
                                                        </Setter.Value>
                                                    </Setter>
                                                    <Trigger.Value>
                                                        <s:Boolean>False</s:Boolean>
                                                    </Trigger.Value>
                                                </Trigger>
                                            </Style.Triggers>
                                            <Style.Resources>
                                                <ResourceDictionary />
                                            </Style.Resources>
                                            <Setter Property="FrameworkElement.MinWidth">
                                                <Setter.Value>
                                                    <s:Double>0</s:Double>
                                                </Setter.Value>
                                            </Setter>
                                            <Setter Property="FrameworkElement.MinHeight">
                                                <Setter.Value>
                                                    <s:Double>0</s:Double>
                                                </Setter.Value>
                                            </Setter>
                                            <Setter Property="FrameworkElement.Width">
                                                <Setter.Value>
                                                    <s:Double>NaN</s:Double>
                                                </Setter.Value>
                                            </Setter>
                                            <Setter Property="FrameworkElement.Height">
                                                <Setter.Value>
                                                    <s:Double>NaN</s:Double>
                                                </Setter.Value>
                                            </Setter>
                                            <Setter Property="Panel.Background">
                                                <Setter.Value>
                                                    <SolidColorBrush>#00FFFFFF</SolidColorBrush>
                                                </Setter.Value>
                                            </Setter>
                                            <Setter Property="Border.BorderBrush">
                                                <Setter.Value>
                                                    <SolidColorBrush>#00FFFFFF</SolidColorBrush>
                                                </Setter.Value>
                                            </Setter>
                                            <Setter Property="Border.BorderThickness">
                                                <Setter.Value>
                                                    <Thickness>2,2,2,2</Thickness>
                                                </Setter.Value>
                                            </Setter>
                                            <Setter Property="Control.Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="ToggleButton">
                                                        <DockPanel LastChildFill="False" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
                                                            <mwt:ClassicBorderDecorator Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" BorderStyle="AltRaised" BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Border" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right">
                                                                <Path Data="M0,0L3.5,4 7,0z" Fill="{TemplateBinding TextElement.Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                                            </mwt:ClassicBorderDecorator>
                                                        </DockPanel>
                                                        <ControlTemplate.Triggers>
                                                            <Trigger Property="ToggleButton.IsChecked">
                                                                <Setter Property="mwt:ClassicBorderDecorator.BorderStyle" TargetName="Border">
                                                                    <Setter.Value>
                                                                        <x:Static Member="mwt:ClassicBorderStyle.AltPressed" />
                                                                    </Setter.Value>
                                                                </Setter>
                                                                <Trigger.Value>
                                                                    <s:Boolean>True</s:Boolean>
                                                                </Trigger.Value>
                                                            </Trigger>
                                                        </ControlTemplate.Triggers>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </ToggleButton.Style>
                                </ToggleButton>
                                <DockPanel Margin="2,2,2,2">
                                    <FrameworkElement Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right" />
                                    <TextBox IsReadOnly="False" HorizontalContentAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding Control.VerticalContentAlignment}" Name="PART_EditableTextBox" Margin="{TemplateBinding Control.Padding}" xml:space="preserve"><TextBox.Style><Style TargetType="TextBox"><Style.Resources><ResourceDictionary /></Style.Resources><Setter Property="FrameworkElement.OverridesDefaultStyle"><Setter.Value><s:Boolean>True</s:Boolean></Setter.Value></Setter><Setter Property="UIElement.AllowDrop"><Setter.Value><s:Boolean>True</s:Boolean></Setter.Value></Setter><Setter Property="FrameworkElement.MinWidth"><Setter.Value><s:Double>0</s:Double></Setter.Value></Setter><Setter Property="FrameworkElement.MinHeight"><Setter.Value><s:Double>0</s:Double></Setter.Value></Setter><Setter Property="FrameworkElement.FocusVisualStyle"><Setter.Value><x:Null /></Setter.Value></Setter><Setter Property="Control.Template"><Setter.Value><ControlTemplate TargetType="TextBox"><ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" Background="#00FFFFFF" Name="PART_ContentHost" Focusable="False" /></ControlTemplate></Setter.Value></Setter></Style></TextBox.Style></TextBox>
                                </DockPanel>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="ItemsControl.HasItems">
                                <Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder">
                                    <Setter.Value>
                                        <s:Double>95</s:Double>
                                    </Setter.Value>
                                </Setter>
                                <Trigger.Value>
                                    <s:Boolean>False</s:Boolean>
                                </Trigger.Value>
                            </Trigger>
                            <Trigger Property="Popup.HasDropShadow" SourceName="PART_Popup">
                                <Setter Property="FrameworkElement.Margin" TargetName="Shdw">
                                    <Setter.Value>
                                        <Thickness>0,0,5,5</Thickness>
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="mwt:SystemDropShadowChrome.Color" TargetName="Shdw">
                                    <Setter.Value>
                                        <Color>#71000000</Color>
                                    </Setter.Value>
                                </Setter>
                                <Trigger.Value>
                                    <s:Boolean>True</s:Boolean>
                                </Trigger.Value>
                            </Trigger>
                            <Trigger Property="UIElement.IsEnabled">
                                <Setter Property="TextElement.Foreground">
                                    <Setter.Value>
                                        <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Panel.Background">
                                    <Setter.Value>
                                        <DynamicResource ResourceKey="{x:Static SystemColors.ControlBrushKey}" />
                                    </Setter.Value>
                                </Setter>
                                <Trigger.Value>
                                    <s:Boolean>False</s:Boolean>
                                </Trigger.Value>
                            </Trigger>
                            <Trigger Property="ItemsControl.IsGrouping">
                                <Setter Property="ScrollViewer.CanContentScroll">
                                    <Setter.Value>
                                        <s:Boolean>False</s:Boolean>
                                    </Setter.Value>
                                </Setter>
                                <Trigger.Value>
                                    <s:Boolean>True</s:Boolean>
                                </Trigger.Value>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Trigger.Value>
                <s:Boolean>True</s:Boolean>
            </Trigger.Value>
        </Trigger>
    </Style.Triggers>
    <Style.Resources>
        <ResourceDictionary />
    </Style.Resources>
    <Setter Property="FrameworkElement.FocusVisualStyle">
        <Setter.Value>
            <Style TargetType="IFrameworkInputElement">
                <Style.Resources>
                    <ResourceDictionary />
                </Style.Resources>
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Rectangle Stroke="#FF000000" StrokeThickness="1" StrokeDashArray="1 2" Margin="4,4,21,4" SnapsToDevicePixels="True" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Setter.Value>
    </Setter>
    <Setter Property="TextElement.Foreground">
        <Setter.Value>
            <DynamicResource ResourceKey="{x:Static SystemColors.WindowTextBrushKey}" />
        </Setter.Value>
    </Setter>
    <Setter Property="Panel.Background">
        <Setter.Value>
            <DynamicResource ResourceKey="{x:Static SystemColors.WindowBrushKey}" />
        </Setter.Value>
    </Setter>
    <Setter Property="FrameworkElement.Margin">
        <Setter.Value>
            <Thickness>0,0,0,0</Thickness>
        </Setter.Value>
    </Setter>
    <Setter Property="Control.Padding">
        <Setter.Value>
            <Thickness>2,1,2,1</Thickness>
        </Setter.Value>
    </Setter>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility">
        <Setter.Value>
            <x:Static Member="ScrollBarVisibility.Auto" />
        </Setter.Value>
    </Setter>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility">
        <Setter.Value>
            <x:Static Member="ScrollBarVisibility.Auto" />
        </Setter.Value>
    </Setter>
    <Setter Property="ScrollViewer.CanContentScroll">
        <Setter.Value>
            <s:Boolean>True</s:Boolean>
        </Setter.Value>
    </Setter>
    <Setter Property="Control.VerticalContentAlignment">
        <Setter.Value>
            <x:Static Member="VerticalAlignment.Center" />
        </Setter.Value>
    </Setter>
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate TargetType="ComboBox">
                <Border BorderThickness="{TemplateBinding Border.BorderThickness}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
                    <Grid>
                        <mwt:ClassicBorderDecorator Background="{TemplateBinding Panel.Background}" BorderStyle="Sunken" BorderBrush="#00FFFFFF" BorderThickness="2,2,2,2" Name="Border">
                            <Popup IsOpen="{TemplateBinding ComboBox.IsDropDownOpen}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" AllowsTransparency="True" Name="PART_Popup" Focusable="False">
                                <mwt:SystemDropShadowChrome Color="#00FFFFFF" Name="Shdw" MinWidth="0" MaxHeight="{TemplateBinding ComboBox.MaxDropDownHeight}">
                                    <Border BorderThickness="1,1,1,1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Name="DropDownBorder">
                                        <ScrollViewer>
                                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained" />
                                        </ScrollViewer>
                                    </Border>
                                </mwt:SystemDropShadowChrome>
                            </Popup>
                        </mwt:ClassicBorderDecorator>
                        <DockPanel Margin="2,2,2,2">
                            <FrameworkElement Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right" />
                            <Border Name="SelectedItemBorder" Margin="{TemplateBinding Control.Padding}">
                                <ContentPresenter Content="{TemplateBinding ComboBox.SelectionBoxItem}" ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}" ContentStringFormat="{TemplateBinding ComboBox.SelectionBoxItemStringFormat}" Margin="1,1,1,1" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </Border>
                        </DockPanel>
                        <ToggleButton IsChecked="False" ClickMode="Press" Width="Auto" MinWidth="0" MinHeight="0" Margin="2,2,2,2" Focusable="False">
                            <ToggleButton.Style>
                                <Style TargetType="ToggleButton">
                                    <Style.Triggers>
                                        <Trigger Property="UIElement.IsEnabled">
                                            <Setter Property="TextElement.Foreground">
                                                <Setter.Value>
                                                    <DynamicResource ResourceKey="{x:Static SystemColors.ControlDarkBrushKey}" />
                                                </Setter.Value>
                                            </Setter>
                                            <Trigger.Value>
                                                <s:Boolean>False</s:Boolean>
                                            </Trigger.Value>
                                        </Trigger>
                                    </Style.Triggers>
                                    <Style.Resources>
                                        <ResourceDictionary />
                                    </Style.Resources>
                                    <Setter Property="FrameworkElement.MinWidth">
                                        <Setter.Value>
                                            <s:Double>0</s:Double>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="FrameworkElement.MinHeight">
                                        <Setter.Value>
                                            <s:Double>0</s:Double>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="FrameworkElement.Width">
                                        <Setter.Value>
                                            <s:Double>NaN</s:Double>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="FrameworkElement.Height">
                                        <Setter.Value>
                                            <s:Double>NaN</s:Double>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="Panel.Background">
                                        <Setter.Value>
                                            <SolidColorBrush>#00FFFFFF</SolidColorBrush>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="Border.BorderBrush">
                                        <Setter.Value>
                                            <SolidColorBrush>#00FFFFFF</SolidColorBrush>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="Border.BorderThickness">
                                        <Setter.Value>
                                            <Thickness>2,2,2,2</Thickness>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="Control.Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="ToggleButton">
                                                <DockPanel LastChildFill="False" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
                                                    <mwt:ClassicBorderDecorator Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" BorderStyle="AltRaised" BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Border" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right">
                                                        <Path Data="M0,0L3.5,4 7,0z" Fill="{TemplateBinding TextElement.Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                                    </mwt:ClassicBorderDecorator>
                                                </DockPanel>
                                                <ControlTemplate.Triggers>
                                                    <Trigger Property="ToggleButton.IsChecked">
                                                        <Setter Property="mwt:ClassicBorderDecorator.BorderStyle" TargetName="Border">
                                                            <Setter.Value>
                                                                <x:Static Member="mwt:ClassicBorderStyle.AltPressed" />
                                                            </Setter.Value>
                                                        </Setter>
                                                        <Trigger.Value>
                                                            <s:Boolean>True</s:Boolean>
                                                        </Trigger.Value>
                                                    </Trigger>
                                                </ControlTemplate.Triggers>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ToggleButton.Style>
                        </ToggleButton>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="ComboBox.IsSelectionBoxHighlighted">
                                <Condition.Value>
                                    <s:Boolean>True</s:Boolean>
                                </Condition.Value>
                            </Condition>
                            <Condition Property="ComboBox.IsDropDownOpen">
                                <Condition.Value>
                                    <s:Boolean>False</s:Boolean>
                                </Condition.Value>
                            </Condition>
                        </MultiTrigger.Conditions>
                        <Setter Property="TextElement.Foreground">
                            <Setter.Value>
                                <DynamicResource ResourceKey="{x:Static SystemColors.HighlightTextBrushKey}" />
                            </Setter.Value>
                        </Setter>
                    </MultiTrigger>
                    <Trigger Property="ComboBox.IsSelectionBoxHighlighted">
                        <Setter Property="Panel.Background" TargetName="SelectedItemBorder">
                            <Setter.Value>
                                <DynamicResource ResourceKey="{x:Static SystemColors.HighlightBrushKey}" />
                            </Setter.Value>
                        </Setter>
                        <Trigger.Value>
                            <s:Boolean>True</s:Boolean>
                        </Trigger.Value>
                    </Trigger>
                    <Trigger Property="ItemsControl.HasItems">
                        <Setter Property="FrameworkElement.MinHeight" TargetName="DropDownBorder">
                            <Setter.Value>
                                <s:Double>95</s:Double>
                            </Setter.Value>
                        </Setter>
                        <Trigger.Value>
                            <s:Boolean>False</s:Boolean>
A: 

The first thing that comes to my mind would be to change the line mentioned below to access the resource as StaticResource. This will give a compilation error if the compiler didn't find the resource. Also, do make sure to define the the resource before the line where you actually use it.

Style="{DynamicResource MyComboStyle}"
Trainee4Life
The resource is found but has the said warning and the combo cannot be opened
codymanix
+1  A: 

Here's the template for ComboBox picked directly from Blend. Let me know if it works.

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
    x:Class="MyComboBoxStyle.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">

    <Window.Resources>
     <Style x:Key="MyComboBoxStyle" TargetType="{x:Type ComboBox}">
      <Setter Property="FocusVisualStyle">
       <Setter.Value>
        <Style>
         <Setter Property="Control.Template">
          <Setter.Value>
           <ControlTemplate>
            <Rectangle Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1" Margin="4,4,21,4" SnapsToDevicePixels="True"/>
           </ControlTemplate>
          </Setter.Value>
         </Setter>
        </Style>
       </Setter.Value>
      </Setter>
      <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
      <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
      <Setter Property="Margin" Value="0"/>
      <Setter Property="Padding" Value="2,1"/>
      <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
      <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
      <Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
      <Setter Property="VerticalContentAlignment" Value="Center"/>
      <Setter Property="Template">
       <Setter.Value>
        <ControlTemplate TargetType="{x:Type ComboBox}">
         <Border SnapsToDevicePixels="True" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
          <Grid>
           <Microsoft_Windows_Themes:ClassicBorderDecorator x:Name="Border" Background="{TemplateBinding Background}" BorderStyle="Sunken" BorderThickness="2">
            <Microsoft_Windows_Themes:ClassicBorderDecorator.BorderBrush>
             <SolidColorBrush/>
            </Microsoft_Windows_Themes:ClassicBorderDecorator.BorderBrush>
            <Popup x:Name="PART_Popup" AllowsTransparency="True" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Focusable="False">
             <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Border}" Color="Transparent">
              <Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1">
               <ScrollViewer>
                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained"/>
               </ScrollViewer>
              </Border>
             </Microsoft_Windows_Themes:SystemDropShadowChrome>
            </Popup>
           </Microsoft_Windows_Themes:ClassicBorderDecorator>
           <DockPanel Margin="2">
            <FrameworkElement Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right"/>
            <Border x:Name="SelectedItemBorder" Margin="{TemplateBinding Padding}">
             <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"/>
            </Border>
           </DockPanel>
           <ToggleButton Margin="2" MinHeight="0" MinWidth="0" Width="Auto" Focusable="False" ClickMode="Press" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
            <ToggleButton.Style>
             <Style TargetType="{x:Type ToggleButton}">
              <Setter Property="MinWidth" Value="0"/>
              <Setter Property="MinHeight" Value="0"/>
              <Setter Property="Width" Value="NaN"/>
              <Setter Property="Height" Value="NaN"/>
              <Setter Property="Background" Value="Transparent"/>
              <Setter Property="BorderBrush">
               <Setter.Value>
                <SolidColorBrush/>
               </Setter.Value>
              </Setter>
              <Setter Property="BorderThickness" Value="2"/>
              <Setter Property="Template">
               <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                 <DockPanel SnapsToDevicePixels="True" Background="{TemplateBinding Background}" LastChildFill="False">
                  <Microsoft_Windows_Themes:ClassicBorderDecorator x:Name="Border" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" BorderBrush="{TemplateBinding BorderBrush}" BorderStyle="AltRaised" BorderThickness="{TemplateBinding BorderThickness}">
                   <Path Fill="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M0,0L3.5,4 7,0z"/>
                  </Microsoft_Windows_Themes:ClassicBorderDecorator>
                 </DockPanel>
                 <ControlTemplate.Triggers>
                  <Trigger Property="IsChecked" Value="True">
                   <Setter Property="BorderStyle" TargetName="Border" Value="AltPressed"/>
                  </Trigger>
                 </ControlTemplate.Triggers>
                </ControlTemplate>
               </Setter.Value>
              </Setter>
              <Style.Triggers>
               <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
               </Trigger>
              </Style.Triggers>
             </Style>
            </ToggleButton.Style>
           </ToggleButton>
          </Grid>
         </Border>
         <ControlTemplate.Triggers>
          <MultiTrigger>
           <MultiTrigger.Conditions>
            <Condition Property="IsSelectionBoxHighlighted" Value="True"/>
            <Condition Property="IsDropDownOpen" Value="False"/>
           </MultiTrigger.Conditions>
           <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
          </MultiTrigger>
          <Trigger Property="IsSelectionBoxHighlighted" Value="True">
           <Setter Property="Background" TargetName="SelectedItemBorder" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
          </Trigger>
          <Trigger Property="HasItems" Value="False">
           <Setter Property="MinHeight" TargetName="DropDownBorder" Value="95"/>
          </Trigger>
          <Trigger Property="IsEnabled" Value="False">
           <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
           <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
          </Trigger>
          <Trigger Property="IsGrouping" Value="True">
           <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
          </Trigger>
          <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
           <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
           <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
          </Trigger>
         </ControlTemplate.Triggers>
        </ControlTemplate>
       </Setter.Value>
      </Setter>
      <Style.Triggers>
       <Trigger Property="IsEditable" Value="True">
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Template">
         <Setter.Value>
          <ControlTemplate TargetType="{x:Type ComboBox}">
           <Border SnapsToDevicePixels="True" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
            <Grid>
             <Microsoft_Windows_Themes:ClassicBorderDecorator x:Name="Border" Background="{TemplateBinding Background}" BorderStyle="Sunken" BorderThickness="2">
              <Microsoft_Windows_Themes:ClassicBorderDecorator.BorderBrush>
               <SolidColorBrush/>
              </Microsoft_Windows_Themes:ClassicBorderDecorator.BorderBrush>
              <Popup x:Name="PART_Popup" AllowsTransparency="True" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Focusable="False">
               <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Border}" Color="Transparent">
                <Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1">
                 <ScrollViewer>
                  <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained"/>
                 </ScrollViewer>
                </Border>
               </Microsoft_Windows_Themes:SystemDropShadowChrome>
              </Popup>
             </Microsoft_Windows_Themes:ClassicBorderDecorator>
             <ToggleButton Margin="2" MinHeight="0" MinWidth="0" Width="Auto" Focusable="False" ClickMode="Press" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
              <ToggleButton.Style>
               <Style TargetType="{x:Type ToggleButton}">
                <Setter Property="MinWidth" Value="0"/>
                <Setter Property="MinHeight" Value="0"/>
                <Setter Property="Width" Value="NaN"/>
                <Setter Property="Height" Value="NaN"/>
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="BorderBrush">
                 <Setter.Value>
                  <SolidColorBrush/>
                 </Setter.Value>
                </Setter>
                <Setter Property="BorderThickness" Value="2"/>
                <Setter Property="Template">
                 <Setter.Value>
                  <ControlTemplate TargetType="{x:Type ToggleButton}">
                   <DockPanel SnapsToDevicePixels="True" Background="{TemplateBinding Background}" LastChildFill="False">
                    <Microsoft_Windows_Themes:ClassicBorderDecorator x:Name="Border" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" BorderBrush="{TemplateBinding BorderBrush}" BorderStyle="AltRaised" BorderThickness="{TemplateBinding BorderThickness}">
                     <Path Fill="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M0,0L3.5,4 7,0z"/>
                    </Microsoft_Windows_Themes:ClassicBorderDecorator>
                   </DockPanel>
                   <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                     <Setter Property="BorderStyle" TargetName="Border" Value="AltPressed"/>
                    </Trigger>
                   </ControlTemplate.Triggers>
                  </ControlTemplate>
                 </Setter.Value>
                </Setter>
                <Style.Triggers>
                 <Trigger Property="IsEnabled" Value="False">
                  <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
                 </Trigger>
                </Style.Triggers>
               </Style>
              </ToggleButton.Style>
             </ToggleButton>
             <DockPanel Margin="2">
              <FrameworkElement Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right"/>
              <TextBox x:Name="PART_EditableTextBox" Margin="{TemplateBinding Padding}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}">
               <TextBox.Style>
                <Style TargetType="{x:Type TextBox}">
                 <Setter Property="OverridesDefaultStyle" Value="True"/>
                 <Setter Property="AllowDrop" Value="True"/>
                 <Setter Property="MinWidth" Value="0"/>
                 <Setter Property="MinHeight" Value="0"/>
                 <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                 <Setter Property="Template">
                  <Setter.Value>
                   <ControlTemplate TargetType="{x:Type TextBox}">
                    <ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="False" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
                   </ControlTemplate>
                  </Setter.Value>
                 </Setter>
                </Style>
               </TextBox.Style>
              </TextBox>
             </DockPanel>
            </Grid>
           </Border>
           <ControlTemplate.Triggers>
            <Trigger Property="HasItems" Value="False">
             <Setter Property="MinHeight" TargetName="DropDownBorder" Value="95"/>
            </Trigger>
            <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
             <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
             <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
             <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
             <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
            </Trigger>
            <Trigger Property="IsGrouping" Value="True">
             <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
            </Trigger>
           </ControlTemplate.Triggers>
          </ControlTemplate>
         </Setter.Value>
        </Setter>
       </Trigger>
      </Style.Triggers>
     </Style>
    </Window.Resources>

    <Grid x:Name="LayoutRoot">
     <ComboBox HorizontalAlignment="Left" Margin="111,156,0,0" Style="{DynamicResource MyComboBoxStyle}" VerticalAlignment="Top" Width="197" Height="25"/>
    </Grid>
</Window>
Trainee4Life
thank you this works :)
codymanix