[英]Find resource from Generic.xaml programmatically
我試圖在WPF和Silverlight中的這篇文章中實現Style Binding 。
我有一個資源字典,generic.Xaml與此代碼:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/AComponent;component/Themes/MyCustomStyles.xaml" />
</ResourceDictionary.MergedDictionaries>
MyCustomStyles.xaml就像這樣開始的地方
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<t:ThemeColorProvider x:Key="ThemeProvider"/>
我需要獲取ThemeProvider的實例來更新我在Generic.xaml中綁定的顏色/畫筆。 是否可以獲取資源的實例鍵入“ThemeProvider”,以便我可以更新它?
如果您了解跨平台WPF和Silverlight實施,則可獲得額外的榮譽!
注意:我需要在聲明Generic.xaml的程序集之外得到它
如果您的資源是在generic.xaml中定義的,或者是在App.xaml中的MergedDictionaries中定義的任何資源,那么您需要使用Application.Current.Resources,例如:
BackgroundColor =(Color)Application.Current.Resources [“ApplicationBarBackgroundColor”]
這可能有所幫助:
ThemeColorProvider value= (ThemeColorProvider)FindResource("ThemeProvider");
// update value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.