尝试将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中创建的标准方式。试图将构建动作设置为资源,但这也不起作用...

我拿到 代码样本 来自微软。它被用来加载页面。任何帮助将不胜感激。

有帮助吗?

解决方案

        Uri uri = new Uri("Themes/Generic.xaml", UriKind.RelativeOrAbsolute);
        var resDict = Application.LoadComponent(uri) as ResourceDictionary;
        this.Resources.MergedDictionaries.Add(resDict);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top