简体   繁体   中英

Use custom namespace in Xaml parsed code

I created a custom control and I'm trying to use this control by using the Xaml Parser in C#, but it seems that the parser doesn't recognize the namespace of the control.

var xaml = @"
<Paragraph
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
    xmlns:d=""http://schemas.microsoft.com/expression/blend/2008""
    xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006""
    xmlns:custom=""using:Sandbox.Custom_Controls""
    mc:Ignorable=""d"">
    <custom:Strike Text=""Lorem ipsum""/>
</Paragraph>";

Paragraph paragraph = (Paragraph)XamlReader.Load(xaml);

The XamlReader throws the following exception: "The type 'Strike' was not found. [Line: 1 Position: 345]".

I tested my control in a normal Xaml file and it works, so it must have something to do width the Xaml Reader.

Have you tried to change this

"xmlns:custom=\"using:Sandbox.Custom_Controls\" " 

to this:

"xmlns:custom=\"clr-namespace:Sandbox.Custom_Controls\" "

?

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