Jump to content
  • Advertisement
Sign in to follow this  

WPF - Button Colour

This topic is 2343 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to change the colour of a button when the mouse is over it, but the following code doesnt seem to work. Even though the property is "IsMouseOver", the colour only changes when the cursor enters, and returns to blue even though the cursor hovers over the button.

<Window x:Class="WpfApplication1.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Button x:Name="button" Content="Button">
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter Property="Button.Background" Value="Red" />

Share this post

Link to post
Share on other sites
Without seeing the rest of your code I can only guess. But I am going to guess, that somewhere else you are turning it back to blue.

Share this post

Link to post
Share on other sites
The reason for this is because the "Background" is actualy a overlay control that's in the default template of the button (this is actually done for a few controls). The actual definition (pulled from the default template I found using a tool on the net) is something like this in the actual style:

<Setter Property="mwt:ButtonChrome.RenderPressed" TargetName="Chrome">

So to actually modify the background on mouse over you have to either A: change the template so the chrome is gone (obviously your control will now look different than the default) or B: find some way to modify the chrome. Unfortunately I don't have any information or time to help you further, but hopefully this points you in the right direction.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!