x:Type and arrays--how?

2019-09-10 08:08发布

Long story short, I need to do this:

ExpressionType="{x:Type sys:Byte[]}"

In other words, I need to do this:

foo.ExpressionType=typeof(byte[]);

Wat do?


Update: Its a bug in the 2010 design surface. It works fine at runtime.

1条回答
贼婆χ
2楼-- · 2019-09-10 08:39

If there is no way to do it in the framework, then you can write your own markup extension:

public class ArrayTypeExtension
    : MarkupExtension
{
    public ArrayTypeExtension() {}

    public ArrayTypeExtension(Type type)
    {
        this.Type = type;
    }

    public Type Type { get; set; }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return Type == null ? null : Type.MakeArrayType();
    }
}

Usage:

ExpressionType="{local:ArrayType sys:Byte}"

Actually, just doing {x:Type sys:Byte[]} seems to work.

查看更多
登录 后发表回答