tags:

views:

31

answers:

1

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, Font-Weight, Font-Size

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

A: 

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
    }
}
Steven Robbins
attached behaviour route? .. perhaps you could elaborate :)
Sonic Soul