public static RoutedEvent RegisterRoutedEvent(string name, RoutingStrategy routingStrategy, Type handlerType, Type ownerType) { lock (Synchronized) { var routedEvent = new RoutedEvent(name, routingStrategy, handlerType, ownerType); AddOwner(routedEvent, ownerType); return routedEvent; } }
public SelectionChangedEventArgs(RoutedEvent id, IList removedItems, IList addedItems) : base(id) { if (removedItems == null) throw new ArgumentNullException("removedItems"); if (addedItems == null) throw new ArgumentNullException("addedItems"); RemovedItems = new object[removedItems.Count]; removedItems.CopyTo((Array) RemovedItems, 0); AddedItems = new object[addedItems.Count]; addedItems.CopyTo((Array) AddedItems, 0); }
public static void AddOwner(RoutedEvent routedEvent, Type ownerType) { lock (Synchronized) { List<RoutedEvent> eventList; if (!_routedEventOwnerDictionary.TryGetValue(ownerType, out eventList)) { eventList = new List<RoutedEvent>(); _routedEventOwnerDictionary.Add(ownerType, eventList); } if (!eventList.Contains(routedEvent)) { eventList.Add(routedEvent); } } }
protected static void ReRaiseEventAs(UIElement sender, RoutedEventArgs args, RoutedEvent newEvent) { if(sender == null) return; if (args == null) throw new ArgumentNullException("args"); if (newEvent == null) throw new ArgumentNullException("newEvent"); var oldEvent = args.RoutedEvent; try { args.RoutedEvent = newEvent; RaiseEventImpl(sender, args); } finally { args.RoutedEvent = oldEvent; } }
/// <summary> /// Removes an <see cref="RoutedEvent"/> handler from this element, using a command stencil as handler. /// </summary> /// <param name="routedEvent">Routed event identifier.</param> /// <param name="handler">Handler of the event.</param> public void RemoveHandler(RoutedEvent routedEvent, ICommandStencil handler) { List<RoutedEventHandlerInfo> handlerList; if (_eventHandlerDictionary.TryGetValue(routedEvent, out handlerList)) { for (var n = 0; n < handlerList.Count; ++n) { if (handlerList[n].CommandStencilHandler == handler) { handlerList.RemoveAt(n); break; } } } }
/// <summary> /// Adds an <see cref="RoutedEvent"/> handler to this element, using a command stencil as handler. /// </summary> /// <param name="routedEvent">Routed event identifier.</param> /// <param name="handler">Handler for the event.</param> /// <param name="handledEventsToo"><c>true</c> if the handler should be invoked for events that has been marked as handled; <c>false</c> for the default behavior.</param> public void AddHandler(RoutedEvent routedEvent, ICommandStencil handler, bool handledEventsToo) { List<RoutedEventHandlerInfo> handlerList; if (!_eventHandlerDictionary.TryGetValue(routedEvent, out handlerList)) { handlerList = new List<RoutedEventHandlerInfo>(1); _eventHandlerDictionary.Add(routedEvent, handlerList); } var handlerInfo = new RoutedEventHandlerInfo(handler, handledEventsToo); handlerList.Add(handlerInfo); }
/// <summary> /// Adds an <see cref="RoutedEvent"/> handler to this element, using a command stencil as handler. /// </summary> /// <param name="routedEvent">Routed event identifier.</param> /// <param name="handler">Handler for the event.</param> public void AddHandler(RoutedEvent routedEvent, ICommandStencil handler) { AddHandler(routedEvent, handler, false); }
/// <summary> /// Adds an <see cref="RoutedEvent"/> handler to this element. /// </summary> /// <param name="routedEvent">Routed event identifier.</param> /// <param name="handler">Handler for the event.</param> public void AddHandler(RoutedEvent routedEvent, Delegate handler) { AddHandler(routedEvent, handler, false); }
public static void RegisterClassHandler(Type classType, RoutedEvent routedEvent, Delegate handler, bool handledEventsToo) { lock (Synchronized) { Dictionary<RoutedEvent, List<RoutedEventHandlerInfo>> classHandlers; if (!_typedClassListeners.TryGetValue(classType, out classHandlers)) { classHandlers = new Dictionary<RoutedEvent, List<RoutedEventHandlerInfo>>(); _typedClassListeners.Add(classType, classHandlers); } List<RoutedEventHandlerInfo> handlerInfoList; if (!classHandlers.TryGetValue(routedEvent, out handlerInfoList)) { handlerInfoList = new List<RoutedEventHandlerInfo>(); classHandlers.Add(routedEvent, handlerInfoList); } var handlerInfo = new RoutedEventHandlerInfo(handler, handledEventsToo); handlerInfoList.Add(handlerInfo); } }
/// <summary> /// Will create an event handler association for the current element, using a command markup extension as handler. /// </summary> /// <param name="obj"><see cref="UIElement"/> which defines the event to assign the event /// handler specified by <paramref name="commandStencil"/> to.</param> /// <param name="evt"><see cref="RoutedEvent"/> which is defined on the class of <paramref name="obj"/>.</param> /// <param name="commandStencil">Command stencil to be used as event handler.</param> protected void HandleEventAssignment(UIElement obj, RoutedEvent evt, ICommandStencil commandStencil) { try { // initialize command extension var evaluableMarkupExtension = commandStencil as IEvaluableMarkupExtension; if (evaluableMarkupExtension != null) { evaluableMarkupExtension.Initialize(this); } // add the event handler to the event obj.AddHandler(evt, commandStencil); } catch (Exception e) { throw new XamlBindingException("Error assigning event handler", e); } }
public static IEnumerable<RoutedEventHandlerInfo> GetTypedClassEventHandlers(Type classType, RoutedEvent routedEvent) { foreach (var classListener in _typedClassListeners) { if (classListener.Key == classType || classType.IsSubclassOf(classListener.Key)) { List<RoutedEventHandlerInfo> handlerInfoList; if (classListener.Value.TryGetValue(routedEvent, out handlerInfoList)) { foreach (var handler in handlerInfoList) { yield return handler; } } } } }
/// <summary> /// REgisteres a class handler for a particular <see cref="RoutedEvent"/>. /// </summary> /// <param name="classType">Type of the class that is declaring class handling. Must not be null.</param> /// <param name="routedEvent">The <see cref="RoutedEvent"/> identifier of the event to handle. Must not be null.</param> /// <param name="handler">A reference to the class handler. Must not be null.</param> public static void RegisterClassHandler(Type classType, RoutedEvent routedEvent, Delegate handler) { RegisterClassHandler(classType, routedEvent, handler, false); }
/// <summary> /// REgisteres a class handler for a particular <see cref="RoutedEvent"/> with the option to handle events that have been marked as handled already. /// </summary> /// <param name="classType">Type of the class that is declaring class handling. Must not be null.</param> /// <param name="routedEvent">The <see cref="RoutedEvent"/> identifier of the event to handle. Must not be null.</param> /// <param name="handler">A reference to the class handler. Must not be null.</param> /// <param name="handledEventsToo"><c>true</c> to invoke the handler, even if the <see>RoutedEventArgs.Handled</see> property has been set to <c>true</c> already; /// <c>false</c> to retain the default behavior of not invoking handled events</param>. public static void RegisterClassHandler(Type classType, RoutedEvent routedEvent, Delegate handler, bool handledEventsToo) { if (classType == null) throw new ArgumentNullException("classType"); if (routedEvent == null) throw new ArgumentNullException("routedEvent"); if (handler == null) throw new ArgumentNullException("handler"); GlobalEventManager.RegisterClassHandler(classType, routedEvent, handler, handledEventsToo); }
/// <summary> /// Initializes a new instance of the RoutedEventArgs class, using the supplied routed event identifier with a different source for the event. /// </summary> /// <param name="routedEvent">The routed event identifier for this <see cref="RoutedEventArgs"/> class.</param> /// <param name="source">An alternate source that is used when the event is handled.</param> public RoutedEventArgs(RoutedEvent routedEvent, object source) { RoutedEvent = routedEvent; Handled = false; Source = source; }
/// <summary> /// Initializes a new instance of the RoutedEventArgs class, using the supplied routed event identifier. /// </summary> /// <param name="routedEvent">The routed event identifier for this <see cref="RoutedEventArgs"/> class.</param> public RoutedEventArgs(RoutedEvent routedEvent) : this(routedEvent, null) { }
/// <summary> /// Will create an event handler association for the current element. /// </summary> /// <remarks> /// In contrast to method /// <see cref="HandleMemberAssignment"/>, /// this method can only be used for the current element, which is part of the /// visual tree. /// </remarks> /// <param name="obj"><see cref="UIElement"/> which defines the event to assign the event /// handler specified by <paramref name="value"/> to.</param> /// <param name="evt"><see cref="RoutedEvent"/> which is defined on the class of /// <paramref name="obj"/>.</param> /// <param name="value">Name of the event handler to assign to the specified /// event.</param> protected void HandleEventAssignment(UIElement obj, RoutedEvent evt, string value) { if (_getEventHandler == null) throw new XamlBindingException("Delegate 'GetEventHandler' is not assigned"); Delegate dlgt = _getEventHandler(this, evt.HandlerType.GetMethod("Invoke"), value); try { obj.AddHandler(evt, dlgt); } catch (Exception e) { throw new XamlBindingException("Error assigning event handler", e); } }
public override void FinishInitialization(IParserContext context) { // if we have a type specified in the event name, we get the RoutedEvent here string localName; string namespaceUri; context.LookupNamespace(Event, out localName, out namespaceUri); var namespaceHandler = context.GetNamespaceHandler(namespaceUri); if (namespaceHandler != null) { int n = localName.IndexOf('.'); if (n >= 0) { var sourceType = namespaceHandler.GetElementType(localName.Substring(0, n), true); var eventName = localName.Substring(n + 1); _routedEvent = EventManager.GetRoutedEventForOwner(sourceType, eventName, true); } // for events without explicit set type, the type and RoutedEvent is looked up in Set/Reset on the target object type. } base.FinishInitialization(context); }