Search code examples
genericsdata-bindingdatacontext

How to set d:DesignInstance to a generic type?


An easy one ;-)

I declared:

     xmlns:om="clr-namespace:System.Collections.ObjectModel;assembly=System"

I try to set a generic as the DataType:

 <DataGrid d:DataContext="{
     d:DesignInstance Type=om:ObservableCollection&lt;System:Int32&gt;}" />

But I'm receiving an error: "Invalid format for a type".

Anybody have an idea how I can do that ?


Solution

  • Generics are not supported yet. We can derive a class from any generics and use that class instead.

    Oops, please see comment below from "Jan 'splite'K". It sounds that there is a markup extension that could do the job.

    Also, look at uli78 link

    Update 2021-09-30 , I think a great answer is given here: How do I set WPF xaml form's Design DataContext to class that uses generic type parameters (thanks to Revious for its comment)