示例#1
0
        /// <summary>
        /// Registers a new routed event.
        /// </summary>
        /// <param name="name">The name of the routed event. The name must be unique within the owner type (base class included) and cannot be null or an empty string.</param>
        /// <param name="routingStrategy">The routing strategy of the event as a value of the enumeration.</param>
        /// <param name="ownerType">The owner class type of the routed event. This cannot be null.</param>
        /// <returns>The identifier for the newly registered routed event.
        /// This identifier object can now be stored as a static field in a class and then used as a parameter for methods that attach handlers to the event.
        /// The routed event identifier is also used for other event system APIs.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="name"/> or <paramref name="ownerType"/> is null.</exception>
        /// <exception cref="InvalidOperationException">This exception is thrown if a routed event of name <paramref name="name"/> already exists for type <paramref name="ownerType"/> and parents.
        /// </exception>
        public static RoutedEvent <T> RegisterRoutedEvent <T>(string name, RoutingStrategy routingStrategy, Type ownerType) where T : RoutedEventArgs
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (ownerType == null)
            {
                throw new ArgumentNullException(nameof(ownerType));
            }

            if (GetRoutedEvent(ownerType, name) != null)
            {
                throw new InvalidOperationException("A routed event named '" + name + "' already exists in provided owner type '" + ownerType + "' or base classes.");
            }

            var newRoutedEvent = new RoutedEvent <T> {
                Name = name, OwnerType = ownerType, RoutingStrategy = routingStrategy,
            };

            lock (SyncRoot)
            {
                RoutedEvents.Add(newRoutedEvent);

                if (!OwnerToEvents.ContainsKey(ownerType))
                {
                    OwnerToEvents[ownerType] = new Dictionary <string, RoutedEvent>();
                }

                OwnerToEvents[ownerType][name] = newRoutedEvent;
            }

            return(newRoutedEvent);
        }
        public void UpdateRoutedEvents(TreeItem treeItem)
        {
            _eventItems.Clear();
            OnEventsChanged();

            foreach (var routedEvent in RoutedEvents)
            {
                routedEvent.Dispose();
            }

            RoutedEvents.Clear();

            if (treeItem != null)
            {
                var fe = treeItem.Instance as FrameworkElement;
                if (fe != null)
                {
                    var routedEvents = EventManager.GetRoutedEvents();
                    if (routedEvents != null)
                    {
                        foreach (RoutedEvent routedEvent in routedEvents)
                        {
                            RoutedEvents.Add(new RoutedEventHandler(routedEvent, fe, AddEvent));
                        }
                    }
                }
            }

            OnRoutedEventsChanged();
        }
 private void AddEventInfo(object sender, RoutedEvents e)
 {
     _mouseActivity += string.Format(
         "{0} sent a {1} event named {2}.\n", sender,
         e.RoutedEvents.RoutingStrategy,
         e.RoutedEvents.Name
         );
 }
        public void btnClickMe_Clicked(object sender, RoutedEvents e)
        {
            AddEventInfo(sender, e);
            System.Windows.Forms.MessageBox.Show(_mouseActivity, "Your event info");

            // clear string for next round;
            _mouseActivity = "";
        }
示例#5
0
 /// <summary>
 /// Returns identifiers for routed events that have been registered to the event system.
 /// </summary>
 /// <returns>An array of type <see cref="RoutedEvent"/> that contains the registered objects.</returns>
 public static RoutedEvent[] GetRoutedEvents()
 {
     return(RoutedEvents.ToArray());
 }
 private void RadioButtonClicked(object sender, RoutedEvents e)
 {
     // TODO: Add event handler implementation here;
 }
 public void btnClickMe_Clicked(object sender, RoutedEvents e)
 {
     System.Windows.Forms.MessageBox.Show("Clicked the button");
 }