Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using System.Type in XAML

Tags:

c#

types

wpf

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

XAML:

<MyUserControl x:Name="TheControl"/>

Code behind:

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

Im looking to be able to do this (XAML only):

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

Is there a way to use typeof inside XAML?

like image 282
Mizipzor Avatar asked Aug 16 '10 12:08

Mizipzor


1 Answers

Use the x:Type Markup Extension:

<MyUserControl 
    xmlns:myns="clr-namespace:My.NameSpace"
    x:Name="TheControl"
    TheType="{x:Type myns:MyType}"/>
like image 157
Quartermeister Avatar answered Oct 03 '22 15:10

Quartermeister