How to use Style.Triggers in Silverlight 4.0?

Migrating from WPF to Silverlight 4.0, I'm stuck with something pretty simple. It seems I could not use a trigger in my styles. How will it work?

eg. here I created a DataGrid ColumnHeader style in my ResourceDictionary:

<Style x:Key="DataGridColumnHeaderStyle" TargetType="sdk:DataGridColumnHeader" > <Setter Property="Background" Value="#88800080" /> <Setter Property="Foreground" Value="White" /> <Style.Triggers> <Trigger Property="SortDirection" Value="{x:Null}"> <Setter Property="Background" Value="{DynamicResource DataGridHeaderBackgroundBrush}" /> <Setter Property="BorderBrush" Value="Transparent" /> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True" /> <Condition Property="SortDirection" Value="{x:Null}" /> </MultiTrigger.Conditions> <Setter Property="Background" Value="{StaticResource DataGridHeaderMouseOverBackgroundBrush}" /> <Setter Property="BorderBrush" Value="{StaticResource DataGridHeaderBorderBrush}" /> </MultiTrigger> ... 

Some Google search attempts since early 2009 require you to use Converters instead, but I'm completely stuck with this. I would really appreciate it if someone could give me a hint on how to do this.

+6
source share
2 answers

Expression Blend has added some support for WPF type triggers in Silverlight. This blog post explains this more.

But, in short, you are not getting the same value with these triggers as with WPF. Meaning, a style trigger can override a parameter explicitly set for an element.

Silverlight uses the VisualStateManager concept for the "theme" or customizes the appearance of the control. This effectively forces you to define “fixed” states, such as Hover (ie IsMouseOver = true) or click. You can then apply the animation when you enter or exit these states. That way, you can tell animate the background brushes when you hover over a parried view.

The VisualStateManager approach simplifies the provision of tools for customizing the appearance of a control. This is described in more detail in this post.

In short, you cannot translate it one on one. You will find many such things. For example, there is no IsMouseOver property in UIElement, as it is in WPF.

+7
source

You must use VisualStateManager .

0
source

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


All Articles