Exception during XamlReader.Load (..)

I get an exception during (UIElement) XamlReader.Load (...) which says

'Cannot create unknown type 'TextBox'.' Line number '1' and line position '2'. 

on the following xaml:

 <TextBox Name="inputMyFirstString" BorderThickness="0" HorizontalAlignment="Stretch" Text="test"></TextBox> 

What did I misunderstand?

+4
source share
3 answers

I think this is due to the missing namespace . Try

 <TextBox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ... 
+4
source

I know this is an old question, but I think the β€œcorrect” answer is still missing. You can avoid changing the XAML by adding the required namespaces to the code:

 ParserContext context = new ParserContext(); context.XmlnsDictionary.Add("","http://schemas.microsoft.com/winfx/2006/xaml/presentation"); context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml"); //etc. object content = XamlReader.Load(stream, context); 
+3
source

Add the xmlns attribute to the Window element in your XAML:

 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ... 
0
source

Source: https://habr.com/ru/post/1301113/


All Articles