简体   繁体   中英

WPF Button what is the right Trigger for me?

I've been trying several properties but I can't seem to get the result I want. Currently, this is what's in my resource dictionary:

<Trigger Property="IsMouseOver" Value="True">
    <Setter TargetName="marker" Property="Fill" Value="Black" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
    <Setter TargetName="marker" Property="Fill" Value="Black" />
</Trigger>

Now whenever I click one of my buttons (there is 4), the marker object turns black. I move my mouse elsewhere and it's still black - so far so good. Now, however, if I click another control on my application, the button loses focus (naturally) and therefore the marker isn't black anymore!

How can this be prevented? I want the marker to stay black when I click the button and once the button loses focus the marker should still stay black until I click the next button.

It sounds more like you're looking for the kind of behaviour you'd get from ToggleButton , where the button is "checked" and "unchecked" by successive clicks.

Try swapping out your Button for a ToggleButton and adding a trigger for the IsChecked property rather than the properties you have now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM