button style
-
Hello,
I have a button which has 2 labels. I want the labels foreground to be black on mouse over button and white when mouse is not over button.
I used this :
<Style TargetType="{x:Type Label}" >
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="false">
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
But the thing is that label foreground is changed only when i am over the label. so one label is black and second is white.How can i solve this so when mouse is over the button, it's children labels will use this style?
-
Hello,
I have a button which has 2 labels. I want the labels foreground to be black on mouse over button and white when mouse is not over button.
I used this :
<Style TargetType="{x:Type Label}" >
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="false">
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
But the thing is that label foreground is changed only when i am over the label. so one label is black and second is white.How can i solve this so when mouse is over the button, it's children labels will use this style?
You only need to supply one trigger. What you do is define the standard style, and as you have a boolean condition, the other condition will be applied when appropriate. Here's what I mean:
<Style TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="Black" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>As you can see, you have a default style which gets overriden by the trigger, and when the trigger no longer applies, it reverts back to the default style.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
-
You only need to supply one trigger. What you do is define the standard style, and as you have a boolean condition, the other condition will be applied when appropriate. Here's what I mean:
<Style TargetType="{x:Type Label}">
<Setter Property="Foreground" Value="Black" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>As you can see, you have a default style which gets overriden by the trigger, and when the trigger no longer applies, it reverts back to the default style.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility
Right but that's not what i meant. I meant that i have a button with 2 labels. But only one of them becomes black when mouse is over one of them , and second label stays white. i want a functionality that when mouse is over the button, both labels will be black.
-
Hello,
I have a button which has 2 labels. I want the labels foreground to be black on mouse over button and white when mouse is not over button.
I used this :
<Style TargetType="{x:Type Label}" >
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="Black"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="false">
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
But the thing is that label foreground is changed only when i am over the label. so one label is black and second is white.How can i solve this so when mouse is over the button, it's children labels will use this style?
Your trigger is applied to a label, not to the button. Because "IsMouseOver" is a property of an individual label, the other label on the button is not influenced. Could you also provide the code of your button?
-
Right but that's not what i meant. I meant that i have a button with 2 labels. But only one of them becomes black when mouse is over one of them , and second label stays white. i want a functionality that when mouse is over the button, both labels will be black.
Ahh, I see. Well, you need to give the label you are interested in a name, and use TargetName in your style trigger setter to change the style. The actual style you have as the main style should be Button not Label.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility