我正在尝试实现 Style Binding from this article in WPF & Silverlight .
我有一个资源字典,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 中绑定(bind)到的颜色/画笔。是否有可能获取资源实例键控“ThemeProvider”以便我可以更新它?
如果您了解跨平台 WPF 和 Silverlight 实现,则加分!
注意:我需要在声明 Generic.xaml 的程序集外部获取这个
最佳答案
如果您的资源是在 generic.xaml 中定义的,或者是在 App.xaml 的 MergedDictionaries 中定义的任何资源,那么您需要使用 Application.Current.Resources,例如:
BackgroundColor = (Color)Application.Current.Resources["ApplicationBarBackgroundColor"]
关于c# - 以编程方式从 Generic.xaml 中查找资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14528622/