Button front panel does not change in property trigger

Why does this trigger work (Changing the mouse on the "Red" button at the end of the mouse)

<Grid> <Grid.Resources> <Style TargetType="{x:Type Button}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Foreground" Value="Red"/> </Trigger> </Style.Triggers> </Style> </Grid.Resources> <Button Content="Hello"/> </Grid> 

but not this trigger, when the foreground of the button is set to color (in this case, “blue”)?

 <Grid> <Grid.Resources> <Style TargetType="{x:Type Button}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Foreground" Value="Red"/> </Trigger> </Style.Triggers> </Style> </Grid.Resources> <Button Foreground="Blue" Content="Hello"/> </Grid> 
+4
source share
2 answers

The local value of the button overrides the style. Try:

 <Grid> <Grid.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="Foreground" Value="Blue"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Foreground" Value="Red"/> </Trigger> </Style.Triggers> </Style> </Grid.Resources> <Button Content="Hello"/> </Grid> 
+6
source

[sp] Yo sé que es un post antiguo pero dejo la respuesta que buscaba el amigo.

[ru] I know this old post, but this solution (in the properties trigger) (Sorry, I don't speak English very well)

answer:

 <Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="Blue"/> 

The most logical way to do this is:

 <Setter Property="Foreground" Value="Blue"/> 

But .. Do not work ..

+2
source

Source: https://habr.com/ru/post/1303154/


All Articles