开发者

x:Type and arrays--how?

开发者 https://www.devze.com 2023-01-07 21:36 出处:网络
Long story short, I need to do this: ExpressionType=\"{x:Type sys:Byte[]}\" In other words, I need to do this:

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[]);

Wa开发者_JS百科t do?


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


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.

0

精彩评论

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