加载 generic.xaml 来合并资源字典时 XamlReader 抛出异常
尝试在代码中加载 generic.xaml 但它抛出 XamlParseException。代码如下:
Uri uri = new Uri("Themes/Generic.xaml", UriKind.Relative);
StreamResourceInfo info = Application.GetResourceStream(uri);
System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader();
ResourceDictionary resdict = (ResourceDictionary)reader.LoadAsync(info.Stream);
this.Resources.MergedDictionaries.Add(resdict);
思路是在一个basepage中合并一个资源字典。然后,派生页面可以使用其基类中的样式、颜色、画笔等,例如使用 {StaticResource DarkBrush}
。
但上面的代码抛出:
'',十六进制值0x0C,是一个无效字符。第 1 行,位置 1。
generic.xaml 文件是在 VS2010 中以标准方式创建的。尝试将“构建操作”设置为“资源”,但这也不起作用...
我得到了 代码示例。在那里它被用来加载页面。任何帮助将不胜感激。
Trying to load generic.xaml in code but it throws a XamlParseException. Code as follows:
Uri uri = new Uri("Themes/Generic.xaml", UriKind.Relative);
StreamResourceInfo info = Application.GetResourceStream(uri);
System.Windows.Markup.XamlReader reader = new System.Windows.Markup.XamlReader();
ResourceDictionary resdict = (ResourceDictionary)reader.LoadAsync(info.Stream);
this.Resources.MergedDictionaries.Add(resdict);
The idea is to merge a resource dictionary in a basepage. Then derived pages can use styles, colors, brushes, etc from their base class by using {StaticResource DarkBrush}
for example.
But the above code throws:
'', hexadecimal value 0x0C, is an invalid character. Line 1, position 1.
The generic.xaml file was created in VS2010 the standard way. Tried to set Build Action to Resource but that didn't work either...
I got the code sample from Microsoft. There it was used to load a page. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)