/// <summary> /// Helper method to remove weakhandler from the list. /// </summary> private static void RemoveKeyTipFocusEventHandler(KeyTipFocusEventHandler handler, List<WeakReference> handlerList) { if (handlerList != null) { lock (handlerList) { for (int i = 0; i < handlerList.Count; i++) { KeyTipFocusEventHandler current = handlerList[i].Target as KeyTipFocusEventHandler; if (current == null || current == handler) { handlerList.RemoveAt(i); i--; } } } } }
/// <summary> /// Helper method to add weakhandler to the list /// </summary> private static void AddKeyTipFocusEventHandler(KeyTipFocusEventHandler handler, ref List<WeakReference> handlerList) { if (handlerList == null) handlerList = new List<WeakReference>(1); lock (handlerList) { // Cleanup the list in case some of the weakEnterMenuModeHandlers is disposed for (int i = 0; i < handlerList.Count; i++) { if (!handlerList[i].IsAlive) { handlerList.RemoveAt(i); i--; } } handlerList.Add(new WeakReference(handler)); } }