private static void OnPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e) { var uie = dpo as UIElement; if (uie == null) { return; } BehaviorCollection itemBehaviors = Interaction.GetBehaviors(uie); var newBehaviors = e.NewValue as StyleBehaviorCollection; var oldBehaviors = e.OldValue as StyleBehaviorCollection; if (newBehaviors == oldBehaviors) { return; } if (oldBehaviors != null) { foreach (var behavior in oldBehaviors) { int index = GetIndexOf(itemBehaviors, behavior); if (index >= 0) { itemBehaviors.RemoveAt(index); } } } if (newBehaviors != null) { foreach (var behavior in newBehaviors) { Guid behaviorId = GetBehaviorId(behavior); int index = GetIndexOf(itemBehaviors, behavior); if (index < 0) { var clone = (Behavior)behavior.Clone(); Guid cloneId = GetBehaviorId(clone); if (cloneId == Guid.Empty) { SetBehaviorId(clone, Guid.NewGuid()); } itemBehaviors.Add(clone); } } } }
private static void OnPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e) { var uie = dpo as FrameworkElement; if (uie == null) { return; } var newBehaviors = e.NewValue as StylizedBehaviorCollection; var oldBehaviors = e.OldValue as StylizedBehaviorCollection; if (newBehaviors == oldBehaviors) { return; } BehaviorCollection itemBehaviors = Interaction.GetBehaviors(uie); uie.Unloaded -= FrameworkElementUnloaded; if (oldBehaviors != null) { foreach (var behavior in oldBehaviors) { int index = GetIndexOf(itemBehaviors, behavior); if (index >= 0) { itemBehaviors.RemoveAt(index); } } } if (newBehaviors != null) { foreach (var behavior in newBehaviors) { int index = GetIndexOf(itemBehaviors, behavior); if (index < 0) { var clone = (Behavior)behavior.Clone(); SetOriginalBehavior(clone, behavior); itemBehaviors.Add(clone); } } } if (itemBehaviors.Count > 0) { uie.Unloaded += FrameworkElementUnloaded; } uie.Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted; }
private static void OnPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e) { var uie = dpo as UIElement; if (uie == null) { return; } BehaviorCollection itemBehaviors = Interaction.GetBehaviors(uie); var newBehaviors = e.NewValue as StylizedBehaviorCollection; var oldBehaviors = e.OldValue as StylizedBehaviorCollection; if (newBehaviors == oldBehaviors) { return; } if (oldBehaviors != null) { foreach (var behavior in oldBehaviors) { int index = itemBehaviors.IndexOf(behavior); if (index >= 0) { itemBehaviors.RemoveAt(index); } } } if (newBehaviors != null) { foreach (var behavior in newBehaviors) { int index = itemBehaviors.IndexOf(behavior); if (index < 0) { if (behavior is ICloneableBehavior) { itemBehaviors.Add((Behavior)((ICloneableBehavior)behavior).CloneBehavior()); } else { throw new NotImplementedException("Behavior does not implement ICloneableBehavior"); } } } } }
private static void OnPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e) { var uie = dpo as UIElement; if (uie == null) { return; } BehaviorCollection itemBehaviors = Interaction.GetBehaviors(uie); var newBehaviors = e.NewValue as StylizedBehaviorCollection; var oldBehaviors = e.OldValue as StylizedBehaviorCollection; if (newBehaviors == oldBehaviors) { return; } if (oldBehaviors != null) { foreach (var behavior in oldBehaviors) { int index = itemBehaviors.IndexOf(behavior); if (index >= 0) { itemBehaviors.RemoveAt(index); } } } if (newBehaviors != null) { foreach (var behavior in newBehaviors) { int index = itemBehaviors.IndexOf(behavior); if (index < 0) { if (behavior.IsFrozen) { itemBehaviors.Add(behavior.Clone() as Behavior); } else { itemBehaviors.Add(behavior); } } } } }
private void OnToggleAnimations(object sender, RoutedEventArgs e) { BehaviorCollection behaviors = Interaction.GetBehaviors(this.text); if (behaviors.Count > 0) { behaviors.RemoveAt(0); } else { behaviors.Add(new ermau.AnimatedTextBoxBehavior()); } }
private static void OnPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e) { var uie = dpo as UIElement; if (uie == null) { return; } BehaviorCollection itemBehaviors = Interaction.GetBehaviors(uie); var newBehaviors = e.NewValue as StylizedBehaviorCollection; var oldBehaviors = e.OldValue as StylizedBehaviorCollection; if (Equals(newBehaviors, oldBehaviors)) { return; } if (oldBehaviors != null) { foreach (var behavior in oldBehaviors) { int index = GetIndexOf(itemBehaviors, behavior); if (index >= 0) { itemBehaviors.RemoveAt(index); } } } if (newBehaviors != null) { foreach (var behavior in newBehaviors) { int index = GetIndexOf(itemBehaviors, behavior); if (index < 0) { var clone = (Behavior)behavior.Clone(); SetOriginalBehavior(clone, behavior); itemBehaviors.Add(clone); } } } }
private static void OnPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { var element = dependencyObject as UIElement; if (element == null) { return; } BehaviorCollection itemBehaviors = Interaction.GetBehaviors(element); var newBehaviors = e.NewValue as CustomBehaviorCollection; var oldBehaviors = e.OldValue as CustomBehaviorCollection; if (Equals(newBehaviors, oldBehaviors)) { return; } if (oldBehaviors != null) { var reduntantBehaviors = oldBehaviors.Select(behavior => GetIndexOf(itemBehaviors, behavior)).Where(index => index >= 0); foreach (var index in reduntantBehaviors) { itemBehaviors.RemoveAt(index); } } if (newBehaviors == null) { return; } foreach (var behavior in newBehaviors) { var index = GetIndexOf(itemBehaviors, behavior); if (index >= 0) { continue; } var clone = (Behavior)behavior.Clone(); SetOriginalBehavior(clone, behavior); itemBehaviors.Add(clone); } }
public static void DetachGestureDetector(this FrameworkElement element) { BehaviorCollection collection = Interaction.GetBehaviors(element); int index = -1; for (int i = 0; i < collection.Count; i++) { if (collection[i].GetType() == typeof(GestureDetectorBehavior)) { index = i; break; } } if (index >= 0) { collection.RemoveAt(index); } }
private static void OnPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e) { UIElement uIElement = dpo as UIElement; if (uIElement == null) { return; } BehaviorCollection behaviors = Interaction.GetBehaviors(uIElement); StylizedBehaviorCollection newValue = e.NewValue as StylizedBehaviorCollection; StylizedBehaviorCollection oldValue = e.OldValue as StylizedBehaviorCollection; if (newValue == oldValue) { return; } if (oldValue != null) { foreach (Behavior behavior in oldValue) { int indexOf = StylizedBehaviors.GetIndexOf(behaviors, behavior); if (indexOf < 0) { continue; } behaviors.RemoveAt(indexOf); } } if (newValue != null) { foreach (Behavior behavior1 in newValue) { if (StylizedBehaviors.GetIndexOf(behaviors, behavior1) >= 0) { continue; } Behavior behavior2 = (Behavior)behavior1.Clone(); StylizedBehaviors.SetOriginalBehavior(behavior2, behavior1); behaviors.Add(behavior2); } } }
private static void OnPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e) { bool designTime = System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject()); if (designTime) { return; } var uie = dpo as UIElement; if (uie == null) { return; } BehaviorCollection itemBehaviors = Interaction.GetBehaviors(uie); var newBehaviors = e.NewValue as StylizedBehaviorCollection; var oldBehaviors = e.OldValue as StylizedBehaviorCollection; if (newBehaviors == oldBehaviors) { return; } if (oldBehaviors != null) { foreach (var behavior in oldBehaviors) { int index = itemBehaviors.IndexOf(behavior); if (index >= 0) { itemBehaviors.RemoveAt(index); } } } if (itemBehaviors != null) { while (itemBehaviors.Count > 0) { itemBehaviors[0].Detach(); itemBehaviors.RemoveAt(0); } } if (newBehaviors != null) { foreach (var behavior in newBehaviors) { int index = itemBehaviors.IndexOf(behavior); if (index < 0) { var dps = GetDependencyProperties(behavior, false); var beh = (Behavior)Activator.CreateInstance(behavior.GetType()); foreach (var dp in dps) { beh.SetValue(dp, behavior.GetValue(dp)); } beh.Attach(dpo); itemBehaviors.Add(beh); } } } }