开发者

Exception while XamlReader.Load(..)

开发者 https://www.devze.com 2022-12-20 12:28 出处:网络
i get an Exception during (UIElement)XamlReader.Load(...) which says \'Ca开发者_开发技巧nnot create unknown type \'TextBox\'.\' Line number \'1\' and line position \'2\'.

i get an Exception during (UIElement)XamlReader.Load(...) which says

'Ca开发者_开发技巧nnot 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?


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);


I think, this is due to missing namespace. Try

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


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

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

精彩评论

暂无评论...
验证码 换一张
取 消