Problem using ArgumentAttribute constructor in WPF

I created my own markup extension as shown below

public class CME: MarkupExtension
{
    private Type _type;
    private string _typeName;

    public CME()
    {
    }

    public CME(Type type, string typeName)
    {
        this._type = type;
        this._typeName = typeName;
    }

    [ConstructorArgument("type")]
    public Type Type
    {
        get
        {
            return this._type;
        }

        set
        {
            this._type = value;
        }
    }

    [ConstructorArgument("typeName")]
    public string TypeName
    {
        get
        {
           return this._typeName;
        }

        set
        {
           this._typeName = value;
        }
    }

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

And I found that I can still use {local:CME {x:Type sys:Boolean},Bool}to create an instance of the CME class in XAML, even I delete all of the ConstructorArgumentAttribute in the CME class.

So, I want to know why we need a ConstructorArgumentAttribute in implementing a custom markup extension or what is the point of a ConstructorArgumentAttribute.

Can anyboday help with this? Many thanks.

+4
source share

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


All Articles