button background not changing wpf
I have a very simple but extremely annoying issue, ive assigned 4 buttons with the same mouse enter event and trying to change their background/foreground/border brush AND NOTHING IS CHANGING IT JUST STAYS THE SAME AS WHENEVER BUTTON IS NORMALLY HIGHLIGHTED!
im 100% sure the event is triggered though as i checked
the only thing i can change about the button is isHitTestVisible
8 Replies
In WPF you should use styles for this. I'll try and find a link
Also please dont use the designer
Nor should you use margins as the tool of doing layouts
Use layout controls, such as DockPanel, Grid, StackPanel, etc.
How exactly do u position elements exactly where u want with layout controls only
I think I need a positioning guide
Margin is the spacing between elements, not absolute position
and even if it was, it would only be a mess if you resized your application
https://wpf-tutorial.com/panels/introduction-to-wpf-panels/
Yea im kinda feeling that
@Azym Equinox here is an example of style triggers https://wpf-tutorial.com/styles/trigger-datatrigger-event-trigger/
NB: I don't see a date on the article itself, and this fits my recollection of using triggers, but syntax may be slightly different in latest versions of wpf.
Here is an example for a really old repo that I did some amateur wpf work in...
https://github.com/devdevdeveau/wpf-timebox/blob/main/TimeBox/MainWindow.xaml
Alright but shouldn't changing properties of button in mouse enter event work too?
It should, yeah, and my proposed fix probably won't work, you've got some ( on the surface ) incompatible features on the button that make it not work. If you get rid of the image content on your buttons it works as expected.
If I copy/paste your code I have the same issue and if I reduce the xaml by removing images and replacing with text content it works as you'd expect.