简体   繁体   中英

Using System.Type in XAML

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?

Use the x:Type Markup Extension :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM