繁体   English   中英

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

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

试图在代码中加载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);

我们的想法是在基页中合并资源字典。 然后派生页面可以使用{StaticResource DarkBrush}作为其基类的样式,颜色,画笔等。

但上面的代码抛出:

'',十六进制值0x0C,是无效字符。 第1行,第1位。

generic.xaml文件是以标准方式在VS2010中创建的。 试图将Build Action设置为Resource,但这也不起作用......

我从Microsoft获得了代码示例 它用于加载页面。 任何帮助将不胜感激。

        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