Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
OnEventCommandBehavior.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.Windows;
4 using System.Windows.Input;
5 
6 namespace SiliconStudio.Presentation.Behaviors
7 {
8  /// <summary>
9  /// An implementation of the <see cref="OnEventBehavior"/> class that allows to invoke a command when a specific event is raised.
10  /// </summary>
12  {
13  /// <summary>
14  /// Identifies the <see cref="Command"/> dependency property.
15  /// </summary>
16  public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(OnEventCommandBehavior));
17 
18  /// <summary>
19  /// Identifies the <see cref="CommandParameter"/> dependency property.
20  /// </summary>
21  public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(object), typeof(OnEventCommandBehavior));
22 
23  /// <summary>
24  /// Gets or sets the command to invoke when the event is raised.
25  /// </summary>
26  public ICommand Command { get { return (ICommand)GetValue(CommandProperty); } set { SetValue(CommandProperty, value); } }
27 
28  /// <summary>
29  /// Gets or sets the parameter of the command to invoke when the event is raised.
30  /// </summary>
31  public object CommandParameter { get { return GetValue(CommandParameterProperty); } set { SetValue(CommandParameterProperty, value); } }
32 
33  /// <inheritdoc/>
34  protected override void OnEvent()
35  {
36  var cmd = Command;
37 
38  if (cmd != null && cmd.CanExecute(CommandParameter))
39  cmd.Execute(CommandParameter);
40  }
41  }
42 }
An abstract behavior that allows to perform actions when an event is raised. It supports both RoutedE...
An implementation of the OnEventBehavior class that allows to invoke a command when a specific event ...
override void OnEvent()
Invoked when the monitored event is raised.