How to set a property in a trigger if it is zero?

How to set a property in a trigger if it is null?

<Style.Triggers> <Trigger Property="ContextMenu" Value="{x:Null}"> <Setter Property="ContextMenu" Value="{DynamicResource ContextMenu}"/> </Trigger> </Style.Triggers> 
+4
source share
2 answers

You can simply install ContextMenu directly in your style like this:

 <Style ...> <Setter Property="ContextMenu" Value="{DynamicResource ContextMenu}"/> </Style> 

If the user explicitly sets ContextMenu, he will take precedence over the style installer. See MSDN Article for ordering or priority. Your style installer is at # 8 and the user parameter is at # 3.

0
source

You tried?

 <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ContextMenu}" Value="{x:Null}"> <Setter Property="ContextMenu" Value="{DynamicResource ContextMenu}"/> </DataTrigger> </Style.Triggers> 

But in fact, you have to configure the context menu in the control style, and then any user of the control can override it in the derived style or in the control attributes.

0
source

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


All Articles