x:Type and arrays--how?

家住魔仙堡 提交于 2019-12-25 06:22:27

问题


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:


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.



来源:https://stackoverflow.com/questions/3268495/xtype-and-arrays-how

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!