Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ButtonCloseWindowBehavior.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.Controls.Primitives;
5 
6 namespace SiliconStudio.Presentation.Behaviors
7 {
8  /// <summary>
9  /// A behavior that can be attached to a <see cref="ButtonBase"/> and will close the window it is contained in when clicked. Note that if a command is attached to the button, it will be executed after the window is closed.
10  /// If you need to execute a command before closing the window, you can use the <see cref="CloseWindowBehavior{T}.Command"/> and <see cref="CloseWindowBehavior{T}.CommandParameter"/> property of this behavior.
11  /// </summary>
12  public class ButtonCloseWindowBehavior : CloseWindowBehavior<ButtonBase>
13  {
14  /// <inheritdoc/>
15  protected override void OnAttached()
16  {
17  base.OnAttached();
18  AssociatedObject.Click += ButtonClicked;
19  }
20 
21  /// <inheritdoc/>
22  protected override void OnDetaching()
23  {
24  AssociatedObject.Click -= ButtonClicked;
25  base.OnDetaching();
26  }
27 
28  /// <summary>
29  /// Raised when the associated button is clicked. Close the containing window
30  /// </summary>
31  private void ButtonClicked(object sender, RoutedEventArgs e)
32  {
33  Close();
34  }
35  }
36 }
A behavior that can be attached to a ButtonBase and will close the window it is contained in when cli...