This project has moved and is read-only. For the latest updates, please go here.

DropDownButton: Easy way to Disable MouseOver and PressedState Chrome Changes

Oct 23, 2014 at 3:59 PM
Greetings Gurus, Basically I set the background color for a DropDown Button in code and I want it to remain that color (I have several DropDownButtons, each needs to remain the same unique color). I don't want hovers, or presses to change the background color I have set.

What should I do? I want the functionality of the button to remain the same BUT the color (chrome) should not change as it does by default to the light blue gradients for hover and darker blue for pressed (drop down open).

Oct 23, 2014 at 8:38 PM

You can redefine the ComponentResourceKey values to be the same as your button's background :
<Style TargetType="{x:Type xctk:DropDownButton}">
            <SolidColorBrush x:Key="{x:Static themes:ResourceKeys.ButtonPressedOuterBorderKey}">Red</SolidColorBrush>
            <SolidColorBrush x:Key="{x:Static themes:ResourceKeys.ButtonPressedBackgroundKey}">Red</SolidColorBrush>
            <SolidColorBrush x:Key="{x:Static themes:ResourceKeys.ButtonMouseOverOuterBorderKey}">Red</SolidColorBrush>
            <SolidColorBrush x:Key="{x:Static themes:ResourceKeys.ButtonMouseOverBackgroundKey}">Red</SolidColorBrush>
         <Setter Property="Background"
                 Value="Red" />

You can redfine the style and templates of ButtonChromes (but this ButtonChrome is used for all buttons) :
-Xceed.Wpf.Toolkit/Chromes/Themes/Aero2.NormalColor.xaml (in Windows8)
-Xceed.Wpf.Toolkit/Chromes/Themes/Generic.xaml (others Windows)
Oct 24, 2014 at 1:35 AM
Excellent BoucherS this is a major step in the right direction.
If you can give an example of assigning a ComponentResourceKey in Code as part of a Code Generated Style, in other words a C# example of the xaml you wrote.

Oct 24, 2014 at 1:58 PM

You can get the resource by the Key and set the color you want :
this.Resources[ Xceed.Wpf.Toolkit.Themes.ResourceKeys.ButtonPressedOuterBorderKey ] = new SolidColorBrush( Colors.Green );
this.Resources[ Xceed.Wpf.Toolkit.Themes.ResourceKeys.ButtonPressedBackgroundKey ] = new SolidColorBrush( Colors.Green );
this.Resources[ Xceed.Wpf.Toolkit.Themes.ResourceKeys.ButtonMouseOverOuterBorderKey ] = new SolidColorBrush( Colors.Green );
this.Resources[ Xceed.Wpf.Toolkit.Themes.ResourceKeys.ButtonMouseOverBackgroundKey ] = new SolidColorBrush( Colors.Green );
Oct 25, 2014 at 12:43 PM
Edited Oct 25, 2014 at 12:52 PM
Bouchers, could you post an example of how to set it to a specific control, like I just want to set these elements for 'DropDownButton_Name' instead of globally applying the settings to every control.
Oct 25, 2014 at 1:20 PM
Thanks BoucherS, I got it: I build this style and apply it to my specific control.
        var aa = new Style(typeof(DropDownButton));
        aa.Resources.Add(Xceed.Wpf.Toolkit.Themes.ResourceKeys.ButtonPressedOuterBorderKey, new SolidColorBrush(Colors.Aqua);