簡體   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