WPF:在不覆盖现有价值的情况下增加保证金 [英] WPF: add to margin without overriding existing value

查看:83
本文介绍了WPF:在不覆盖现有价值的情况下增加保证金的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义了两种简单的边距样式,一种基于另一种样式.

I have two simple margin styles defined, one based off 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>

在派生的'marginIndentStyle'样式中,我希望将页边距的Left支柱调整为比基本'marginStyle'样式中的Left支柱大10,即比当前设置多10.使用上面的like会完全覆盖这些值.我只想添加它,以使派生的'marginIndentStyle'样式的结果边距为"10,10,20,10".

In the derived 'marginIndentStyle' style, I want adjust the margin's Left prop to be 10 more than the Left prop in the base 'marginStyle' style, that is 10 more than what it is currently set at. Using a like above overrides the values completely. I just want to add to it such that the resultant margin for the derived 'marginIndentStyle' style is "10,10,20,10".

请注意,我不想将其值严格设置为10、10、20、10 b/c,我希望对'marginStyle'样式的任何更改都可以反映在派生的'marginIndentStyle'样式中.

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

这可能吗?

推荐答案

AFAIK,如果没有大量代码,这是不可能的.

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

一种更简单的方法是将两种具有静态边距的样式应用于两个不同的面板\装饰器.

An easier way will be to have two styles with static margins that are applied to two different panels\decorators.

类似的东西:

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

这将有效地增加利润率.因此,第二个边界中的边界将具有第一和第二边界的组合.

This, effectively, will compound the margins. So what ever is in the second border will have the margin as combination of the first and the second margins.

这篇关于WPF:在不覆盖现有价值的情况下增加保证金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆