目前我得到與WPF資源交手,不知道如果你能幫助我:WPF ContentControl中的內容沒有得到家長資源
我有一個包含自己的資源WPF窗口。它還包含一個內容控件,它根據在樹視圖中選擇的內容來更改其內容,例如:
contentControl1.Content = someUserControl;
這可以是一個UserControl,例如, SomeUserControl
它使用我在窗口xaml中定義的靜態資源。
當在後面的窗口代碼中創建SomeUserControl
的實例時,我得到一個XMLParseException('在'System.Windows.StaticResourceExtension'上提供值'拋出異常')。這是包含綁定到靜態資源的行。
爲了解決這個問題,我已將此添加SomeUserControl的構造(parentResources是從那裏someUserControl實例化窗口的資源):
public SomeUserControl(ResourceDictionary parentResources)
{
this.Resources.MergedDictionaries.Add(parentResources);
InitializeComponent();
}
這是在這種特殊情況下尋找資源的最佳方法?謝謝你的幫助。
您好,感謝您的建議:不,這不利於,而不是我得到:A「DynamicResourceExtension」不能在'轉換器「結合」類型的屬性設置。 'DynamicResourceExtension'只能在DependencyObject的DependencyProperty上設置。 - 我目前正在綁定轉換器我寫過 – Jeb 2012-04-19 13:25:53