Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SetFocusOnLoadBehavior.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 using System.Collections.Generic;
5 using System.Linq;
6 using System.Text;
7 using System.Windows;
8 using System.Windows.Interactivity;
9 
10 namespace SiliconStudio.Presentation.Behaviors
11 {
12  public class SetFocusOnLoadBehavior : Behavior<FrameworkElement>
13  {
14  protected override void OnAttached()
15  {
16  if (AssociatedObject.IsLoaded)
17  AssociatedObject.Focus();
18  else
19  AssociatedObject.Loaded += OnHostLoaded;
20  }
21 
22  protected override void OnDetaching()
23  {
24  AssociatedObject.Loaded -= OnHostLoaded;
25  }
26 
27  private void OnHostLoaded(object sender, RoutedEventArgs e)
28  {
29  AssociatedObject.Focus();
30  }
31  }
32 }