简体   繁体   English

加载generic.xaml以合并资源字典时,XamlReader抛出

[英]XamlReader throws when loading generic.xaml to merge resource dictionaries

Trying to load generic.xaml in code but it throws a XamlParseException. 试图在代码中加载generic.xaml但它会抛出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. 然后派生页面可以使用{StaticResource DarkBrush}作为其基类的样式,颜色,画笔等。

But the above code throws: 但上面的代码抛出:

'', hexadecimal value 0x0C, is an invalid character. '',十六进制值0x0C,是无效字符。 Line 1, position 1. 第1行,第1位。

The generic.xaml file was created in VS2010 the standard way. generic.xaml文件是以标准方式在VS2010中创建的。 Tried to set Build Action to Resource but that didn't work either... 试图将Build Action设置为Resource,但这也不起作用......

I got the code sample from Microsoft. 我从Microsoft获得了代码示例 There it was used to load a page. 它用于加载页面。 Any help would be greatly appreciated. 任何帮助将不胜感激。

        Uri uri = new Uri("Themes/Generic.xaml", UriKind.RelativeOrAbsolute);
        var resDict = Application.LoadComponent(uri) as ResourceDictionary;
        this.Resources.MergedDictionaries.Add(resDict);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM