Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Interaction.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 
5 namespace SiliconStudio.Presentation.Interactivity
6 {
7  /// <summary>
8  /// A container for an attached dependency property that contains a collection of behavior.
9  /// The purpose of this class is to be used in place of System.Windows.Interactivity.Interaction.
10  /// This class allows to set behaviors in styles because <see cref="SiliconStudio.Presentation.Interactivity.BehaviorCollection"/>
11  /// has a public parameterless constructor and the Behaviors attached property has a public setter.
12  /// When the collection is modified or set, it automatically synchronize the attached property
13  /// System.Windows.Interactivity.Interaction.Behaviors.
14  /// </summary>
15  public static class Interaction
16  {
17  public static readonly DependencyProperty BehaviorsProperty = DependencyProperty.RegisterAttached("Behaviors", typeof(BehaviorCollection), typeof(Interaction), new PropertyMetadata(new BehaviorCollection(), OnBehaviorCollectionChanged));
18 
20  {
21  return (BehaviorCollection)obj.GetValue(BehaviorsProperty);
22  }
23 
24  public static void SetBehaviors(DependencyObject obj, BehaviorCollection value)
25  {
26  obj.SetValue(BehaviorsProperty, value);
27  }
28 
29  private static void OnBehaviorCollectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
30  {
31  var oldValue = (BehaviorCollection)e.OldValue;
32  if (oldValue != null)
33  oldValue.Detach();
34 
35  var newValue = (BehaviorCollection)e.NewValue;
36  if (newValue != null)
37  {
38  if (newValue.AssociatedObject != null)
39  newValue = newValue.Clone();
40 
41  newValue.Attach(d);
42  }
43  }
44  }
45 }
A collection of behavior that synchronize with the System.Windows.Interactivity.Interaction.Behaviors attached property.
static BehaviorCollection GetBehaviors(DependencyObject obj)
Definition: Interaction.cs:19
A container for an attached dependency property that contains a collection of behavior. The purpose of this class is to be used in place of System.Windows.Interactivity.Interaction. This class allows to set behaviors in styles because SiliconStudio.Presentation.Interactivity.BehaviorCollection has a public parameterless constructor and the Behaviors attached property has a public setter. When the collection is modified or set, it automatically synchronize the attached property System.Windows.Interactivity.Interaction.Behaviors.
Definition: Interaction.cs:15
static void SetBehaviors(DependencyObject obj, BehaviorCollection value)
Definition: Interaction.cs:24