我有一個Windows 10通用應用程序,包含一些樣式等資源字典。 在一個這樣的資源字典中,我有一個顏色,我想通過後面的代碼訪問MyBlue
。這是如何實現的?從ResourceDictionary中檢索代碼後面的代碼
我試過this.Resources["MyBlue"]
,但由於MyBlue
是在單獨的資源字典中定義的,而不是直接在頁面資源中定義,所以它不存在於這個集合中。
這裏是我的App.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/PodStyles.xaml"/>
<ResourceDictionary Source="Styles/ButtonStyles.xaml"/>
<ResourceDictionary Source="Styles/OfferStyles.xaml"/>
<ResourceDictionary Source="Styles/MyStyles.xaml"/>
<ResourceDictionary>
<!--Global View Model Locator-->
<vm:ViewModelLocator x:Key="Locator"
d:IsDataSource="True"/>
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
你能分享你的app.xaml嗎?這不應該是必要的。 – moswald
@moswald補充說。 – earthling
呃......:困惑:我不知道。這看起來是正確的,你應該可以通過查看應用程序的資源來實現它。 – moswald