Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DependencyProperty value inheritance
Message
De
12/06/2009 06:38:26
 
 
À
12/06/2009 05:31:56
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01405435
Message ID:
01405437
Vues:
43
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform