2011-04-10 58 views
1

對於CustomControl的Resources屬性,它的內容來自哪裏以及如何在XAML中爲其添加資源? Themes/Generic.xaml是最好的地方嗎?我是否需要在控件的代碼中進行某種資源合併?派生自CustomControl的類從哪裏獲取其資源?

以下代碼可以實時加載資源,但如果經常調用它,我認爲這可能會很慢。

System.Uri resourceLocater = new System.Uri("/Themes/Generic.xaml", System.UriKind.Relative); 
ResourceDictionary d = (ResourceDictionary)Application.LoadComponent(resourceLocater); 

回答

0

你可以把在默認樣式的Style.Resources資源,但是這些reasources的訪問本來也應該僅限於樣式中。如果僅在Template內需要它們,則還可以使用ControlTemplate.Resources