>> 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:
void cbEditData_Executed(object sender, ExecutedRoutedEventArgs e) { LLCanvas lla = MethodToGrabCurrentCanvas(); MenuItem mi = e.Parameter as MenuItem; if (mi != null) { if (mi.IsChecked) lla.ControlMode = ControlMode.DataEdit; else ((DependencyObject)lla).ClearValue(CMProp.ControlModeProperty); } }but it feels like a kludge - there should be some way of doing this within the dependency property callbacks......