/// <summary> /// Is called when the id of an object is changed. /// </summary> /// <param name="d">Object</param> /// <param name="e">Event args</param> /// <remarks> /// Adds the object to a dictionary with all hosts and registers an Initialized event handler. /// </remarks> /// <exception cref="ArgumentException">Attached property 'Id' con only be applied to ItemsControls or ToolBarTrays</exception> private static void OnIdChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // check if object is an ItemsControl or ToolBarTray (is a must for menu hosts) if (!(d is ItemsControl) && !(d is ToolBarTray)) { throw new ArgumentException( "Attached property \'Id\' con only be applied to ItemsControls or ToolBarTrays"); } var oldId = (string)e.OldValue; var newId = (string)e.NewValue; // string s; // unregister with old id (if possible) if (!MergeMenusExt.IsNullOrWhiteSpace(oldId) && _MergeHosts.ContainsKey(oldId)) { MergeHost host; if (_MergeHosts.TryGetValue(oldId, out host)) { host.HostElement = null; _MergeHosts.Remove(oldId); } } // register with new id if (!MergeMenusExt.IsNullOrWhiteSpace(newId)) { var host = new MergeHost(newId); host.HostElement = d as FrameworkElement; _MergeHosts.Add(newId, host); } }
/// <summary> /// Is called when the id of an object is changed. /// </summary> /// <param name="d">Object</param> /// <param name="e">Event args</param> /// <remarks> /// Adds the object to a dictionary with all hosts and registers an Initialized event handler. /// </remarks> /// <exception cref="ArgumentException">Attached property 'Id' con only be applied to ItemsControls or ToolBarTrays</exception> private static void OnIdChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { // check if object is an ItemsControl or ToolBarTray (is a must for menu hosts) if (!(d is ItemsControl) && !(d is ToolBarTray)) { throw new ArgumentException( "Attached property \'Id\' con only be applied to ItemsControls or ToolBarTrays"); } var oldId = (string)e.OldValue; var newId = (string)e.NewValue; // string s; // unregister with old id (if possible) if (!MergeMenusExt.IsNullOrWhiteSpace(oldId) && _MergeHosts.ContainsKey(oldId)) { MergeHost host; if (_MergeHosts.TryGetValue(oldId, out host)) { host.HostElement = null; _MergeHosts.Remove(oldId); } } // register with new id if (!MergeMenusExt.IsNullOrWhiteSpace(newId)) { var host = new MergeHost(newId); host.HostElement = d as FrameworkElement; _MergeHosts.Add(newId, host); } }