x:类型和数组-如何? [英] x:Type and arrays--how?

查看:71
本文介绍了x:类型和数组-如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长话短说,我需要这样做:

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

做什么?

更新:这是2010年设计图面中的错误.在运行时效果很好.

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();
    }
}

用法:

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

实际上,仅执行{x:Type sys:Byte []}似乎可行.

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

这篇关于x:类型和数组-如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆