Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception while XamlReader.Load(..)

Tags:

c#

xaml

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 wrong?

like image 847
elCapitano Avatar asked Feb 12 '10 13:02

elCapitano


2 Answers

I know this is an old question but I think the "right" answer is still missing. You can avoid changing your XAML by adding the required namespaces in 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);
like image 199
Manfred Radlwimmer Avatar answered Oct 26 '22 00:10

Manfred Radlwimmer


I think, this is due to missing namespace. Try

<TextBox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ...
like image 21
Anton Gogolev Avatar answered Oct 26 '22 01:10

Anton Gogolev