Call bindings for DependencyObject when DependencyProperites are changed

Posted by melculetz on Stack Overflow See other posts from Stack Overflow or by melculetz
Published on 2010-04-08T20:20:51Z Indexed on 2010/04/08 20:23 UTC
Read the original article Hit count: 501

Is there a way to notify a DependencyObject's bindinigs when the inner DependencyProperties have changed?

For example, I have this class:

public class BackgroundDef : DependencyObject
    {
        public static readonly DependencyProperty Color1Property =
            DependencyProperty.Register("Color1", typeof(Color),
                typeof(Background), new UIPropertyMetadata(Colors.White));

        public static readonly DependencyProperty UseBothColorsProperty =
            DependencyProperty.Register("UseBothColors", typeof(bool),
                typeof(Background), new UIPropertyMetadata(false));

        public static readonly DependencyProperty Color2Property =
            DependencyProperty.Register("Color2", typeof(Color),
                typeof(Background), new UIPropertyMetadata(Colors.White));

        public Color Color1
        {
            set { SetValue(Color1Property, value); }
            get { return (Color)GetValue(Color1Property); }
        }

        public bool UseBothColors
        {
            set { SetValue(UseBothColorsProperty, value); }
            get { return (bool)GetValue(UseBothColorsProperty); }
        }

        public Color Color2
        {
            set { SetValue(Color2Property, value); }
            get { return (Color)GetValue(Color2Property); }
        }
    }

For which I have 3 separate two-way bindings that set the values for Color1, Color2 and UseBothColors. But I also have a binding for a BackgroundDef instance, which should create a Brush and draw the background of a button (either a single color, or two gradient colors). My problem is that the two-way bindings for the DependencyProperties update the properties, but the binding for the class instance is not called, as apparently the entire object does not change. Any idea how I could call the bindings for the DependencyObject when the DependencyProperties are changed?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about dependency-properties