WPF: adding to margin without overriding an existing value

I have two simple field styles, one of which is based on the other.

<Style x:Key="marginStyle" TargetType="FrameworkElement"> <Setter Property="Margin" Value="0,10,20,10"/> </Style> <!-- based on marginStyle --> <Style x:Key="marginIndentStyle" TargetType="FrameworkElement" BasedOn="{StaticResource marginStyle}"> <Setter Property="Margin" Value="10,0,0,0"/> </Style> 

In the derived marginIndentStyle style, I want to adjust the margin of Left prop to 10 more than the left margin in the basic marginStyle style, which is 10 more than at the moment. Using such a function completely overrides the values. I just want to add to it such that the resulting margin for the marginIndentStyle derived style is "10,10,20,10".

Note. I do not want to strictly set its value to 10,10,20,10 b / c. I want any changes to the marginStyle style to be reflected in the derived marginIndentStyle style.

Is it possible?

0
source share
1 answer

AFAIK, this is not possible without a significant amount of code.

A simpler way is to have two styles with static fields that apply to two different panels \ decorators.

Sort of:

 <Border Style="{StaticResource marginIndentStyle}"> <Border Style="{StaticResource marginStyle}"> ..... </Border> </Border> 

This, in fact, will make up the fields. Thus, whatever is on the second border, the margin will be both a combination of the first and second fields.

+1
source

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


All Articles