Using System.Type in XAML

I need to be able to set a property of type System.Type in UserControl. Im currently doing this:

XAML:

<MyUserControl x:Name="TheControl"/>

Code behind:

TheControl.TheType = typeof(My.NameSpace.MyType);

I would like to do this (XAML only):

<MyUserControl x:Name="TheControl" TheType="??"/>

Is there any way to use typeofinside XAML?

+5
source share
1 answer

Use x: Type Markup Extension :

<MyUserControl 
    xmlns:myns="clr-namespace:My.NameSpace"
    x:Name="TheControl"
    TheType="{x:Type myns:MyType}"/>
+11
source

All Articles