Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
RoutedEventArgs.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 namespace SiliconStudio.Paradox.UI.Events
6 {
7  /// <summary>
8  /// Contains state information and event data associated with a routed event.
9  /// </summary>
10  public class RoutedEventArgs : EventArgs
11  {
12  /// <summary>
13  /// Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.
14  /// </summary>
15  public bool Handled { get; set; }
16 
17  private RoutedEvent routedEvent;
18 
19  private UIElement source;
20 
21  protected bool IsBeingRouted { get; private set; }
22 
23  /// <summary>
24  /// Gets or sets the <see cref="RoutedEvent"/> associated with this RoutedEventArgs instance.
25  /// </summary>
26  /// <exception cref="InvalidOperationException">Attempted to change the RoutedEvent value while the event is being routed.</exception>
27  public RoutedEvent RoutedEvent
28  {
29  get { return routedEvent; }
30  set
31  {
32  if(IsBeingRouted)
33  throw new InvalidOperationException("The routed event cannot be changed while the event is being routed.");
34 
35  routedEvent = value;
36  }
37  }
38 
39  /// <summary>
40  /// Gets or sets a reference to the object that raised the event.
41  /// </summary>
42  /// <exception cref="InvalidOperationException">Attempted to change the source value while the event is being routed.</exception>
43  public UIElement Source
44  {
45  get { return source; }
46  set
47  {
48  if (IsBeingRouted)
49  throw new InvalidOperationException("The routed event cannot be changed while the event is being routed.");
50 
51  source = value;
52  }
53  }
54 
55  /// <summary>
56  /// Indicate to the <see cref="RoutedEventArgs"/> that the event has started being routed.
57  /// </summary>
58  internal void StartEventRouting()
59  {
60  IsBeingRouted = true;
61  }
62 
63  /// <summary>
64  /// Indicate to the <see cref="RoutedEventArgs"/> that the event has ended being routed.
65  /// </summary>
66  internal void EndEventRouting()
67  {
68  IsBeingRouted = false;
69  }
70 
71  /// <summary>
72  /// Initializes a new instance of the RoutedEventArgs class.
73  /// </summary>
74  /// <remarks>
75  /// When using this parameterless constructor, all public properties of the new <see cref="RoutedEventArgs"/> instance assume the following default values:
76  /// <see cref="RoutedEvent"/> = null, <see cref="Handled"/> = false, <see cref="Source"/> = null.
77  /// Null values for <see cref="Source"/> only mean that the <see cref="RoutedEventArgs"/> data makes no attempt to specify the source.
78  /// When this instance is used in a call to <see cref="UIElement.RaiseEvent"/>, the <see cref="Source"/> value is populated based on the element
79  /// that raised the event and are passed on to listeners through the routing.
80  /// </remarks>
81  public RoutedEventArgs()
82  : this(null, null)
83  {
84  }
85  /// <summary>
86  /// Initializes a new instance of the RoutedEventArgs class, using the supplied routed event identifier.
87  /// </summary>
88  /// <param name="routedEvent">The routed event identifier for this instance of the <see cref="RoutedEventArgs"/> class.</param>
89  /// <remarks>
90  /// When using this constructor, unspecified public properties of the new <see cref="RoutedEventArgs"/> instance assume the following default values:
91  /// <see cref="Handled"/> = false, <see cref="Source"/> = null.
92  /// Null values for <see cref="Source"/> only mean that the <see cref="RoutedEventArgs"/> data makes no attempt to specify the source.
93  /// When this instance is used in a call to <see cref="UIElement.RaiseEvent"/>, the <see cref="Source"/> value is populated based on the element
94  /// that raised the event and are passed on to listeners through the routing.
95  /// </remarks>
96  public RoutedEventArgs(RoutedEvent routedEvent)
97  :this(routedEvent, null)
98  {
99  }
100 
101  /// <summary>
102  /// Initializes a new instance of the <see cref="RoutedEventArgs"/> class, using the supplied routed event identifier, and providing the opportunity to declare a different source for the event.
103  /// </summary>
104  /// <param name="routedEvent">The routed event identifier for this instance of the <see cref="RoutedEventArgs"/> class.</param>
105  /// <param name="source">An alternate source that will be reported when the event is handled. This pre-populates the <see cref="Source"/> property.</param>
106  /// <remarks>
107  /// When using this constructor, unspecified public properties of the new <see cref="RoutedEventArgs"/> instance assume the following default values:
108  /// <see cref="Handled"/> = false.</remarks>
109  public RoutedEventArgs(RoutedEvent routedEvent, UIElement source)
110  {
111  RoutedEvent = routedEvent;
112  Source = source;
113  }
114  }
115 }
RoutedEventArgs(RoutedEvent routedEvent, UIElement source)
Initializes a new instance of the RoutedEventArgs class, using the supplied routed event identifier...
Provides a base class for all the User Interface elements in Paradox applications.
Definition: UIElement.cs:21
Contains state information and event data associated with a routed event.
Represents and identifies a routed event and declares its characteristics.
Definition: RoutedEvent.cs:10
RoutedEventArgs()
Initializes a new instance of the RoutedEventArgs class.
RoutedEventArgs(RoutedEvent routedEvent)
Initializes a new instance of the RoutedEventArgs class, using the supplied routed event identifier...