We have an existing application which is extensively styled throughout and utuilizes a common resource dictionary which contains keyed brushes defined as static resources.
We would like to bind the color values of our solid color resource brushes to the colors of brushes in your theme libraries. We need to change the color pallate of our application to reflect the colors of an ActiPro theme.
I've tried sub-classing a brush (which is not supported by the framework), dynamic markup extensions and standard markup extensions. All have failed due to the delayed nature of the dynamic resource binding strategy.
The only way I have been able bind the color value of our static brushes to the color of a brush in your theme library is through an attached property I registered as "SourceBrush" (Example below).
Problem: We have thousands of styled elements being rendered and updated. Having each one look up the Dynamic Resource of the designated brush key is straining our system.
Question: Is there a better (more efficient) way to implement just the color pallate of your theme(s) using the static brushes defined in our resource dictionary?
Example Follows:
<SolidColorBrush x:Key="GridBackground"
PresentationOptions:Freeze="True"
extensions:ThemeProperties.SourceBrush="{DynamicResource
{x:Static themes:AssetResourceKeys.ControlBackgroundNormalBrushKey}}" />
public class ThemeProperties : DependencyObject
{
public static readonly DependencyProperty
SourceBrushProperty =
DependencyProperty.RegisterAttached(
"SourceBrush", typeof(SolidColorBrush), typeof(ThemeProperties),
new PropertyMetadata(CallBackWhenPropertyIsChanged));
public static SolidColorBrush GetSourceBrush(
DependencyObject d)
{
return (SolidColorBrush)d.GetValue(SourceBrushProperty);
}
public static void SetSourceBrush(
DependencyObject d, SolidColorBrush value)
{
d.SetValue(SolidColorBrush.ColorProperty, value.Color);
}
private static void CallBackWhenPropertyIsChanged(
object sender,
DependencyPropertyChangedEventArgs args)
{
var attachedObject = sender as SolidColorBrush;
if (attachedObject != null)
{
attachedObject.Color = ((SolidColorBrush) args.NewValue).Color;
}
}
}
[Modified 10 years ago]