/// <summary> /// Retrieves the mapping collection /// </summary> /// <param name="obj"></param> /// <returns></returns> public static CommandEventCollection GetMappings(DependencyObject obj) { var map = obj.GetValue(MappingsProperty) as CommandEventCollection; if (map == null) { map = new CommandEventCollection(); SetMappings(obj, map); } return(map); }
/// <summary> /// This changes the event mapping /// </summary> /// <param name="target"></param> /// <param name="e"></param> private static void OnMappingsChanged(DependencyObject target, DependencyPropertyChangedEventArgs e) { if (e.OldValue != null) { CommandEventCollection cec = e.OldValue as CommandEventCollection; if (cec != null) { cec.Unsubscribe(target); } } if (e.NewValue != null) { CommandEventCollection cec = e.NewValue as CommandEventCollection; if (cec != null) { cec.Subscribe(target); } } }
/// <summary> /// This sets the mapping collection. /// </summary> /// <param name="obj">Dependency Object</param> /// <param name="value">Mapping collection</param> public static void SetMappings(DependencyObject obj, CommandEventCollection value) { obj.SetValue(MappingsProperty, value); }