Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DependencyProperty value inheritance
Message
From
12/06/2009 06:38:26
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01405435
Message ID:
01405437
Views:
42
>Hi,
>I have created a custom attached dependency property:
>    public class CMProp : DependencyObject
>    {
>        public static readonly DependencyProperty ControlModeProperty;
>
>        static CMProp()
>        {
>            FrameworkPropertyMetadata fm = new FrameworkPropertyMetadata();
>            fm.Inherits = true;
>            fm.DefaultValue = ControlMode.Display;
>            ControlModeProperty = DependencyProperty.RegisterAttached("ControlMode", typeof(LLControls.ControlMode), typeof(CMProp), fm);
>        }
>
>        public static void SetControlMode(UIElement element, LLControls.ControlMode value)
>        {
>            element.SetValue(ControlModeProperty, value);
>        }
>
>        public static LLControls.ControlMode GetControlMode(UIElement element)
>        {
>            return (LLControls.ControlMode)element.GetValue(ControlModeProperty);
>        }
>     }
ControlMode is an enum with three values: Display, HeaderEdit and DataEdit. I am using the dependency property on a sub-classed canvas:
public static readonly DependencyProperty ControlModeProperty;
>static LLCanvas()
>{
>FrameworkPropertyMetadata p5 = new FrameworkPropertyMetadata();
>p5.Inherits = true;
>ControlModeProperty = CMProp.ControlModeProperty.AddOwner(typeof(LLCanvas), p5);
>}
In use these canvases can be nested so, for example:
>CanvasA
>-->CanvasB
>---->CanvasC
>
>If I set the ControlMode on CanvasA this flows through and is inherited by CanvasB and CanvasC as expected. If, however I set the ControlMode on CanvasB then, obviously, since I have set a local value there then subsequent changes on CanvasA are not inherited (which is fine).
>But if I set the ControlMode of CanvasB to ControlMode.Display I want it to return to using the inherited value of CanvasA.
>AFAICS I can't do this in the CoerceValue callback. I also tried using ClearValue() in the PropertyChanged callback but that doesn't appear to work either.
>
>Any suggestions on how to accomplish this?
>TIA,
>Viv


I would if I could - you're way ahead
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform