Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array of Type in xaml?

Tags:

wpf

xaml

is there a way to declare an array of types in xaml?

maybe something like this?

 <x:Array Type="x:Type">
   <x:Type se:MyType1/> 
   <x:Type se:MyType2/> 
   <x:Type se:MyType3/>                                                                    
 </x:Array>
like image 485
icube Avatar asked Oct 21 '25 03:10

icube


1 Answers

You need to use a different namespace prefix. x:Type is a markup extension that creates System.Type objects, and you want to create an array of type objects, not an array of markup extensions (I assume).

You cannot call constructors from when using element syntax, so you'll need to pass the type in using the Type property of TypeExtension.

Something like this should work:

<x:Array xmlns:sys="clr-namespace:System;assembly=mscorlib" Type="sys:Type">
    <x:Type Type="se:MyType1"/>
    <x:Type Type="se:MyType2"/>
    <x:Type Type="se:MyType3"/>
</x:Array>
like image 115
Quartermeister Avatar answered Oct 26 '25 04:10

Quartermeister