我在 (UIElement)XamlReader.Load(...) 期间得到一个异常
'Cannot create unknown type 'TextBox'.' Line number '1' and line position '2'.
在以下 xaml 上:
<TextBox Name="inputMyFirstString" BorderThickness="0" HorizontalAlignment="Stretch" Text="test"></TextBox>
我做错了什么?
最佳答案
我知道这是一个老问题,但我认为“正确”的答案仍然缺失。 您可以通过在代码中添加所需的命名空间来避免更改 XAML:
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);
关于c# - XamlReader.Load(..) 时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2252222/