views:

20

answers:

1

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  A: 

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.

Quartermeister
I'm afraid this is going to end up the correct answer...
Will
@Will: Actually, just doing `{x:Type sys:Byte[]}` seems to work for me. What's happening when you try it?
Quartermeister
You must not be generating the error correctly (?!?!). You should get the error "Type sys:Byte[] not found." It will build, but fails when run. Try adding `DataContext="{x:Type sys:Byte[]}"` to a new WPF forms project and run it.
Will
VS2008; New Project / WPF Application; add `<ContentControl xmlns:sys="clr-namespace:System;assembly=mscorlib" Content="{x:Type sys:Byte[]}"/>` to the Grid and run; I get a window that displays 'System.Byte[]'.
Quartermeister
That explains it. Its a bug in 2010. I can run it, but I get that exception when I hit it in the designer. I'll pass it along to MS. Accepting.
Will