2010-07-16 37 views
0

长话短说,我需要这样做:x:类型和数组 - 如何?

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

换句话说,我需要这样做:

foo.ExpressionType=typeof(byte[]); 

笏吗?


更新:它是2010设计界面中的一个错误。它在运行时正常工作。

回答

1

如果没有办法做到这一点的框架,那么您可以编写自己的标记扩展:

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:键入SYS :Byte []}似乎工作。

+0

恐怕这会最终得到正确答案...... – Will 2010-07-16 20:34:58

+0

@威尔:其实,只是在做'{x:Type sys:Byte []}'似乎对我很有用。当你尝试时发生了什么? – Quartermeister 2010-07-16 20:44:30

+0

您不能正确生成错误(?!?!)。您应该得到错误“未找到类型sys:Byte []”。“它会生成,但运行时会失败。尝试添加'DataContext =“{x:输入sys:Byte []}”'到一个新的WPF表单项目并运行它。 – Will 2010-07-16 20:47:06