开发者

wpf converter : setting multiple properties

I am used to using converters that return a value per property, such as Foreground color.

Is it possible to have a converter that works with multiple properties?

such as: Foreground, Background, Fon开发者_如何学运维t-Weight, Font-Size

How can I create one converter (or less than 4) that could set multiple properties?


No, converters aren't designed for that. You could possibly go down the attached behaviour route and set the properties, based on a bound dependency property (I assume) on attach?

Edit: behaviours are part of the Blend SDK, the basic structure of what you want is:

public class MyBehavior : Behavior<TextBlock>
{
    //// <-- Dependency property here

    protected override void OnAttached()
    {
        base.OnAttached();

        this.AssociatedObject.Foreground = CalculateForeground();
        this.AssociatedObject.Background = CalculateBackground();
        // etc..
    }

    private Brush CalculateForeground()
    {
        // Do some calculations based on the dependency property
    }

    private Brush CalculateBackground()
    {
        // Do some calculations based on the dependency property
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();

        // You  might want to reset to default here, or just do nothing
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜