Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MarkupExtension: changing constructor argument is not evaluated in design time

Here is how it looks like:

When changing markup extension Key property - everything works.

When changing markup extension constructor argument - it's not updated. Workaround is to update property with extension (change Text) and then back. Then value is evaluated correctly.

Here is extension:

public class MyExtension : MarkupExtension
{
    public string Key { get; set; }

    public MyExtension() { }

    public MyExtension(string key)
    {
        Key = key;
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return Key;
    }
}

Any ideas of how to make designer work with constructor argument same way as it does with property?

like image 893
Sinatr Avatar asked Jan 01 '26 02:01

Sinatr


1 Answers

What seems to remedy this situation is the use of ConstructorArgumentAttribute like so:

public class MyExtension : MarkupExtension
{
    [ConstructorArgument("key")]
    public string Key { get; set; }

    public MyExtension() { }

    public MyExtension(string key)
    {
        Key = key;
    }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return Key;
    }
}
like image 92
Markus Hütter Avatar answered Jan 02 '26 14:01

Markus Hütter