示例#1
0
        protected override void OnAttached()
        {
            base.OnAttached();

            Triggers            = Interaction.GetTriggers(AssociatedObject);
            CloseDialogsCommand = new DelegateCommand(p => OnCloseDialogsCommandExecuted());
        }
示例#2
0
        /// <summary>
        /// Gets the TriggerCollection containing the triggers associated with the specified object.
        ///
        /// </summary>
        /// <param name="obj">The object from which to retrieve the triggers.</param>
        /// <returns>
        /// A TriggerCollection containing the triggers associated with the specified object.
        /// </returns>
        public static TriggerCollection GetTriggers(DependencyObject obj)
        {
            TriggerCollection triggerCollection = (TriggerCollection)obj.GetValue(Interaction.TriggersProperty);

            if (triggerCollection == null)
            {
                triggerCollection = new TriggerCollection();
                triggerCollection.Attach(obj); //CSHTML5 Added
                obj.SetValue(Interaction.TriggersProperty, triggerCollection);
            }
            return(triggerCollection);
        }
示例#3
0
        /// <summary>
        /// Gets the collection of triggers for the specified DependencyObject.
        /// </summary>
        /// <param name="o">The DependencyObject to lookup.</param>
        /// <returns>The collection of associated triggers.</returns>
        public static TriggerCollection GetTriggers(DependencyObject o)
        {
            TriggerCollection triggers = (TriggerCollection)o.GetValue(TriggersProperty);

            if (triggers == null)
            {
                triggers = new TriggerCollection(o);
                SetTriggers(o, triggers);
            }

            return(triggers);
        }
        /// <summary>
        /// This is called when the triggers collection is altered via a Style.
        /// </summary>
        /// <param name="dpo"></param>
        /// <param name="e"></param>
        private static void OnTriggersPropertyChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e)
        {
            var uie = dpo as UIElement;

            if (uie == null)
            {
                return;
            }

            // Get the old and new trigger set.
            var oldTriggers = e.OldValue as IList <TriggerBase>;
            var newTriggers = e.NewValue as IList <TriggerBase>;

            // Get the actual System.Interaction collection
            TriggerCollection itemTriggers = Interaction.GetTriggers(uie);

            // Remove any old triggers
            if (oldTriggers != null)
            {
                foreach (var trigger in oldTriggers)
                {
                    if (newTriggers == null || !newTriggers.Contains(trigger))
                    {
                        itemTriggers.Remove(trigger);
                    }
                }
            }

            // Add new triggers
            if (newTriggers != null)
            {
                foreach (TriggerBase trigger in newTriggers)
                {
                    if (!itemTriggers.Contains(trigger))
                    {
                        var thisTrigger = trigger;
                        if (thisTrigger.IsFrozen)
                        {
                            thisTrigger = (TriggerBase)trigger.Clone();
                            foreach (var a in trigger.Actions)
                            {
                                var thisAction = (TriggerAction)a.Clone();
                                thisTrigger.Actions.Add(thisAction);
                            }
                        }
                        itemTriggers.Add(thisTrigger);
                    }
                }
            }
        }
示例#5
0
        private static void OnTriggersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            System.Windows.Interactivity.TriggerCollection triggers = System.Windows.Interactivity.Interaction.GetTriggers(d);
            foreach (System.Windows.Interactivity.TriggerBase trigger in e.NewValue as StyleTriggerCollection)
            {
                System.Windows.Interactivity.TriggerBase triggerClone = (System.Windows.Interactivity.TriggerBase)trigger.Clone();
                foreach (System.Windows.Interactivity.TriggerAction action in trigger.Actions)
                {
                    System.Windows.Interactivity.TriggerAction actionClone = (System.Windows.Interactivity.TriggerAction)action.Clone();
                    triggerClone.Actions.Add(actionClone);
                }

                triggers.Add(triggerClone);
            }
        }
示例#6
0
        /// <summary>
        /// This is called when the behavior collection is changed on an object.
        /// </summary>
        /// <param name="dpo">FrameworkElement owner</param>
        /// <param name="e"></param>
        private static void OnTriggerListChanged(DependencyObject dpo, DependencyPropertyChangedEventArgs e)
        {
            TriggerCollection list = e.OldValue as TriggerCollection;

            if (list != null)
            {
                list.Detach();
            }

            list = e.NewValue as TriggerCollection;
            FrameworkElement fe = dpo as FrameworkElement;

            if (list != null && fe != null)
            {
                list.Attach(fe);
            }
        }
示例#7
0
        public static void DetachEventTriggerAction(this DependencyObject dpObj)
        {
            if (dpObj == null)
            {
                return;
            }

            Interactivity.TriggerCollection triggerCollection = Interactivity.Interaction.GetTriggers(dpObj);
            if (triggerCollection != null && triggerCollection.Count == 0)
            {
                return;
            }
            foreach (var triggerAction in triggerCollection)
            {
                triggerAction.Detach();
            }
        }
示例#8
0
        /// <summary>
        /// Gets the action associated with the specified Button.
        /// </summary>
        /// <param name="button">The Button to lookup.</param>
        /// <returns>The action associated with the Button; null if there is none.</returns>
        public static TriggerAction GetAction(ButtonBase button)
        {
            TriggerCollection triggers = (TriggerCollection)button.GetValue(TriggersProperty);

            if (triggers != null)
            {
                foreach (Trigger trigger in triggers)
                {
                    ClickTrigger clickTrigger = trigger as ClickTrigger;
                    if (clickTrigger != null)
                    {
                        return(clickTrigger.Action);
                    }
                }
            }

            return(null);
        }
示例#9
0
        public void ShouldFireTriggersOnPropertyChanged()
        {
            PropertyTrigger trigger = new PropertyTrigger()
            {
                PropertyName = "HorizontalAlignment"
            };

            MockAction action = new MockAction();

            trigger.Actions.Add(action);
            FrameworkElement element = new FrameworkElement();

            System.Windows.Interactivity.TriggerCollection triggers = Interaction.GetTriggers(element);
            triggers.Add(trigger);

            element.HorizontalAlignment = HorizontalAlignment.Left;

            Assert.IsTrue(action.hasExecuted);
            Assert.IsTrue(action.IsAttached);
        }
        private static void OnTemplateChanged(
            DependencyObject d,
            DependencyPropertyChangedEventArgs e)
        {
            InteractivityTemplate dt = (InteractivityTemplate)e.NewValue;

        #if (!SILVERLIGHT)
            dt.Seal();
        #endif
            InteractivityItems ih = (InteractivityItems)dt.LoadContent();
            BehaviorCollection bc = Interaction.GetBehaviors(d);
            System.Windows.Interactivity.TriggerCollection tc = Interaction.GetTriggers(d);
            foreach (Behavior behavior in ih.Behaviors)
            {
                bc.Add(behavior);
            }
            foreach (System.Windows.Interactivity.TriggerBase trigger in ih.Triggers)
            {
                tc.Add(trigger);
            }
        }
示例#11
0
        /// <summary>
        /// Sets the action associated with the specified Button.
        /// </summary>
        /// <param name="button">The Button to associate the action with.</param>
        /// <param name="action">The action to associate with the button.</param>
        public static void SetAction(ButtonBase button, TriggerAction action)
        {
            if (action == null)
            {
                return;
            }

            TriggerCollection triggers = GetTriggers(button);

            foreach (Trigger trigger in triggers)
            {
                ClickTrigger clickTrigger = trigger as ClickTrigger;
                clickTrigger.Action = action;
            }

            ClickTrigger newTrigger = new ClickTrigger();

            newTrigger.Action = action;

            triggers.Add(newTrigger);
        }
示例#12
0
        private InvokableCallMethodAction _callMethodAction; // action used to invoke the method

        public InvokeMethodTimer()
        {
            // Create a CallMethodAction to handle invoking the method.  Use the InvokableCallMethodAction
            // class so that the Invoke method can be invoked programmatically.
            _callMethodAction = new InvokableCallMethodAction();

            // Bind the action's MethodName and TargetObject properties to the corresponding properties
            // on the InvokeMethodTimer object
            Binding b = new Binding("MethodName")
            {
                Source = this
            };

            BindingOperations.SetBinding(_callMethodAction, CallMethodAction.MethodNameProperty, b);

            b = new Binding("TargetObject")
            {
                Source = this
            };
            BindingOperations.SetBinding(_callMethodAction, CallMethodAction.TargetObjectProperty, b);

            // Add the CallMethodAction to the InvokeMethodTimer's triggers collection.  Without this,
            // invoking the action will fail silently.
            Interactivity.EventTrigger trigger = new Interactivity.EventTrigger();
            trigger.Actions.Add(_callMethodAction);
            Interactivity.TriggerCollection triggers = Interactivity.Interaction.GetTriggers(this);
            triggers.Add(trigger);

            // Initialize the timer
            _timer = new DispatcherTimer()
            {
                Interval = Delay
            };
            _timer.Tick += (o, e) =>
            {
                _timer.Stop();
                _callMethodAction.Invoke(null);
            };
        }
示例#13
0
 /// <summary>
 /// Sets the behavior list.
 /// </summary>
 /// <param name="obj">Object to set behavior collection on</param>
 /// <param name="value">Collection to assign</param>
 public static void SetTriggers(DependencyObject obj, TriggerCollection value)
 {
     obj.SetValue(TriggersProperty, value);
 }
示例#14
0
 /// <summary>
 /// Sets the collection of triggers for the specified DependencyObject.
 /// </summary>
 /// <param name="o">The DependencyObject to set.</param>
 /// <param name="triggers">The collection of triggers to associate.</param>
 public static void SetTriggers(DependencyObject o, TriggerCollection triggers)
 {
     o.SetValue(TriggersProperty, triggers);
 }
示例#15
0
        /// <summary>
        /// Gets the collection of triggers for the specified DependencyObject.
        /// </summary>
        /// <param name="o">The DependencyObject to lookup.</param>
        /// <returns>The collection of associated triggers.</returns>
        public static TriggerCollection GetTriggers(DependencyObject o)
        {
            TriggerCollection triggers = (TriggerCollection)o.GetValue(TriggersProperty);
            if (triggers == null) {
                triggers = new TriggerCollection(o);
                SetTriggers(o, triggers);
            }

            return triggers;
        }
示例#16
0
 /// <summary>
 /// Sets the collection of triggers for the specified DependencyObject.
 /// </summary>
 /// <param name="o">The DependencyObject to set.</param>
 /// <param name="triggers">The collection of triggers to associate.</param>
 public static void SetTriggers(DependencyObject o, TriggerCollection triggers)
 {
     o.SetValue(TriggersProperty, triggers);
 }
示例#17
0
        public override void OnApplyTemplate()
        {
            this.CombateGrid = this.GetTemplateChild("CombateGrid") as Grid;
            if (this.CombateGrid == null)
            {
                return;
            }

            foreach (BoardField field in Board.Layout)
            {
                var rect = new Rectangle
                {
                    Stroke = Brushes.Black,
                };

                var rectStyle = new Style(typeof(Rectangle));

                var defaultFill            = new Setter(Shape.FillProperty, Brushes.Transparent);
                var defaultStrokethickness = new Setter(Shape.StrokeThicknessProperty, 1.0);
                var defaultHitTest         = new Setter(IsHitTestVisibleProperty, true);

                rectStyle.Setters.Add(defaultFill);
                rectStyle.Setters.Add(defaultStrokethickness);
                rectStyle.Setters.Add(defaultHitTest);

                var unwalkableFill            = new Setter(Shape.FillProperty, Brushes.Blue);
                var unwalkableStrokeThickness = new Setter(Shape.StrokeThicknessProperty, 0.0);
                var unwalkableHitTest         = new Setter(IsHitTestVisibleProperty, false);
                var unwalkableTrigger         = new DataTrigger
                {
                    Binding = new Binding("IsWalkable")
                    {
                        Source = field
                    },
                    Value = false
                };
                unwalkableTrigger.Setters.Add(unwalkableFill);
                unwalkableTrigger.Setters.Add(unwalkableStrokeThickness);
                unwalkableTrigger.Setters.Add(unwalkableHitTest);

                var attackableFill = new Setter
                {
                    Property = Shape.FillProperty,
                    Value    = Brushes.Red
                };
                var atackableTrigger = new DataTrigger
                {
                    Binding = new Binding("IsAttackable")
                    {
                        Source = field
                    },
                    Value = true
                };
                atackableTrigger.Setters.Add(attackableFill);

                var enabledFill = new Setter
                {
                    Property = Shape.FillProperty,
                    Value    = Brushes.SpringGreen
                };
                var enabledTrigger = new DataTrigger
                {
                    Binding = new Binding("IsEnabled")
                    {
                        Source = field
                    },
                    Value = true
                };
                enabledTrigger.Setters.Add(enabledFill);

                rectStyle.Triggers.Add(unwalkableTrigger);
                rectStyle.Triggers.Add(atackableTrigger);
                rectStyle.Triggers.Add(enabledTrigger);

                rect.Style = rectStyle;

                var clickDownEvent = new EventToCommand
                {
                    Command          = this.Vm.FieldClickDownCommand,
                    CommandParameter = field
                };
                var triggerEvent = new InteractiveEventTrigger
                {
                    EventName = "MouseLeftButtonDown",
                };
                triggerEvent.Actions.Add(clickDownEvent);
                TriggerCollection triggers = Interaction.GetTriggers(rect);
                triggers.Add(triggerEvent);

                Grid.SetColumn(rect, field.Column);
                Grid.SetRow(rect, field.Row);
                Panel.SetZIndex(rect, 1);
                this.CombateGrid.Children.Add(rect);
            }

            foreach (BoardPiece piece in SelfPlayer.Army)
            {
                var button = new Button
                {
                    BorderThickness  = new Thickness(3),
                    BorderBrush      = Brushes.Black,
                    FontWeight       = FontWeights.Bold,
                    Command          = this.Vm.PieceClickCommand,
                    CommandParameter = piece
                };

                var buttonStyle = new Style(typeof(Button))
                {
                    BasedOn = FindResource("MetroCircleButtonStyle") as Style
                };

                var defaultBackground = new Setter(BackgroundProperty, Brushes.Gray);
                var defaultVisibility = new Setter(VisibilityProperty, Visibility.Collapsed);
                var defaultEffect     = new Setter(EffectProperty, null);
                var defaultForeground = new Setter(ForegroundProperty, Brushes.Black);
                var defaultFontSize   = new Setter(FontSizeProperty, 12.0);

                buttonStyle.Setters.Add(defaultBackground);
                buttonStyle.Setters.Add(defaultVisibility);
                buttonStyle.Setters.Add(defaultEffect);
                buttonStyle.Setters.Add(defaultForeground);
                buttonStyle.Setters.Add(defaultFontSize);

                var player1Setter = new Setter(BackgroundProperty, TryFindResource("Player1Brush"));
                var player2Setter = new Setter(BackgroundProperty, TryFindResource("Player2Brush"));

                var isOpponentCondition = new Condition
                {
                    Binding = new Binding("IsOpponent")
                    {
                        Source = piece
                    },
                    Value = true
                };
                var isSelfPlayerCondition = new Condition
                {
                    Binding = new Binding("IsOpponent")
                    {
                        Source = piece
                    },
                    Value = false
                };
                var opponentIsPlayer1 = new Condition
                {
                    Binding = new Binding("IsPlayer2")
                    {
                        Source = this.Vm.Opponent
                    },
                    Value = false
                };
                var selfPlayerIsPlayer1 = new Condition
                {
                    Binding = new Binding("IsPlayer2")
                    {
                        Source = this.Vm.SelfPlayer
                    },
                    Value = false
                };
                var opponentIsPlayer2 = new Condition
                {
                    Binding = new Binding("IsPlayer2")
                    {
                        Source = this.Vm.Opponent
                    },
                    Value = true
                };
                var selfPlayerIsPlayer2 = new Condition
                {
                    Binding = new Binding("IsPlayer2")
                    {
                        Source = this.Vm.SelfPlayer
                    },
                    Value = true
                };

                var player1Trigger1 = new MultiDataTrigger();
                player1Trigger1.Conditions.Add(isOpponentCondition);
                player1Trigger1.Conditions.Add(opponentIsPlayer1);
                player1Trigger1.Setters.Add(player1Setter);

                var player1Trigger2 = new MultiDataTrigger();
                player1Trigger2.Conditions.Add(isSelfPlayerCondition);
                player1Trigger2.Conditions.Add(selfPlayerIsPlayer1);
                player1Trigger2.Setters.Add(player1Setter);

                var player2Trigger1 = new MultiDataTrigger();
                player2Trigger1.Conditions.Add(isOpponentCondition);
                player2Trigger1.Conditions.Add(opponentIsPlayer2);
                player2Trigger1.Setters.Add(player2Setter);

                var player2Trigger2 = new MultiDataTrigger();
                player2Trigger2.Conditions.Add(isSelfPlayerCondition);
                player2Trigger2.Conditions.Add(selfPlayerIsPlayer2);
                player2Trigger2.Setters.Add(player2Setter);

                var visibilitySetter  = new Setter(VisibilityProperty, Visibility.Visible);
                var visibilityTrigger = new DataTrigger
                {
                    Binding = new Binding("IsAlive")
                    {
                        Source = piece
                    },
                    Value = true
                };
                visibilityTrigger.Setters.Add(visibilitySetter);

                var effectSetter  = new Setter(EffectProperty, new DropShadowEffect());
                var effectTrigger = new DataTrigger
                {
                    Binding = new Binding("IsSelected")
                    {
                        Source = piece
                    },
                    Value = true
                };
                effectTrigger.Setters.Add(effectSetter);

                var onAttackFontSizeSetter = new Setter(FontSizeProperty, button.FontSize * 2.0);

                var winningForegroundSetter = new Setter(ForegroundProperty, Brushes.Green);
                var winningTrigger          = new DataTrigger
                {
                    Binding = new Binding("IsDefeating")
                    {
                        Source = piece
                    },
                    Value = true
                };
                winningTrigger.Setters.Add(onAttackFontSizeSetter);
                winningTrigger.Setters.Add(winningForegroundSetter);

                var defeatStoryboard = new Storyboard
                {
                    AccelerationRatio = 0.2
                };
                defeatStoryboard.Completed += (s, _) => DefeatStoryboard_Completed();
                var defeatAnimation = new DoubleAnimation(0.1, new TimeSpan(0, 0, 0, 2, 0));
                Storyboard.SetTarget(defeatAnimation, button);
                Storyboard.SetTargetProperty(defeatAnimation, new PropertyPath(FontSizeProperty));
                defeatStoryboard.Children.Add(defeatAnimation);
                var beginSb = new BeginStoryboard
                {
                    Storyboard = defeatStoryboard,
                    Name       = "DefeatStoryboard"
                };
                var stopSb = new StopStoryboard
                {
                    BeginStoryboardName = beginSb.Name
                };
                var losingForegroundSetter = new Setter(ForegroundProperty, Brushes.Red);
                var losingTrigger          = new DataTrigger
                {
                    Binding = new Binding("IsBeingDefeated")
                    {
                        Source = piece
                    },
                    Value = true
                };
                losingTrigger.EnterActions.Add(beginSb);
                losingTrigger.ExitActions.Add(stopSb);
                losingTrigger.Setters.Add(onAttackFontSizeSetter);
                losingTrigger.Setters.Add(losingForegroundSetter);

                buttonStyle.Triggers.Add(player1Trigger1);
                buttonStyle.Triggers.Add(player1Trigger2);
                buttonStyle.Triggers.Add(player2Trigger1);
                buttonStyle.Triggers.Add(player2Trigger2);
                buttonStyle.Triggers.Add(visibilityTrigger);
                buttonStyle.Triggers.Add(effectTrigger);
                buttonStyle.Triggers.Add(winningTrigger);
                buttonStyle.Triggers.Add(losingTrigger);

                buttonStyle.RegisterName(beginSb.Name, beginSb);
                button.Style = buttonStyle;

                ApplyBinding("Column", piece, button, Grid.ColumnProperty);
                ApplyBinding("Row", piece, button, Grid.RowProperty);
                ApplyBinding("PowerLevel", piece, button, ContentProperty);

                Panel.SetZIndex(button, 2);
                this.CombateGrid.Children.Add(button);
            }

            foreach (BoardPiece piece in Opponent.Army)
            {
                var button = new Button
                {
                    Effect           = null,
                    BorderThickness  = new Thickness(3),
                    BorderBrush      = Brushes.Black,
                    FontWeight       = FontWeights.Bold,
                    IsHitTestVisible = false
                };

                var buttonStyle = new Style(typeof(Button))
                {
                    BasedOn = FindResource("MetroCircleButtonStyle") as Style
                };

                var defaultBackground = new Setter(BackgroundProperty, Brushes.Gray);
                var defaultVisibility = new Setter(VisibilityProperty, Visibility.Collapsed);
                var defaultForeground = new Setter(ForegroundProperty, Brushes.Black);
                var defaultFontSize   = new Setter(FontSizeProperty, 12.0);

                buttonStyle.Setters.Add(defaultBackground);
                buttonStyle.Setters.Add(defaultVisibility);
                buttonStyle.Setters.Add(defaultForeground);
                buttonStyle.Setters.Add(defaultFontSize);

                var player1Setter = new Setter(BackgroundProperty, TryFindResource("Player1Brush"));
                var player2Setter = new Setter(BackgroundProperty, TryFindResource("Player2Brush"));

                var isOpponentCondition = new Condition
                {
                    Binding = new Binding("IsOpponent")
                    {
                        Source = piece
                    },
                    Value = true
                };
                var isSelfPlayerCondition = new Condition
                {
                    Binding = new Binding("IsOpponent")
                    {
                        Source = piece
                    },
                    Value = false
                };
                var opponentIsPlayer1 = new Condition
                {
                    Binding = new Binding("IsPlayer2")
                    {
                        Source = this.Vm.Opponent
                    },
                    Value = false
                };
                var selfPlayerIsPlayer1 = new Condition
                {
                    Binding = new Binding("IsPlayer2")
                    {
                        Source = this.Vm.SelfPlayer
                    },
                    Value = false
                };
                var opponentIsPlayer2 = new Condition
                {
                    Binding = new Binding("IsPlayer2")
                    {
                        Source = this.Vm.Opponent
                    },
                    Value = true
                };
                var selfPlayerIsPlayer2 = new Condition
                {
                    Binding = new Binding("IsPlayer2")
                    {
                        Source = this.Vm.SelfPlayer
                    },
                    Value = true
                };

                var player1Trigger1 = new MultiDataTrigger();
                player1Trigger1.Conditions.Add(isOpponentCondition);
                player1Trigger1.Conditions.Add(opponentIsPlayer1);
                player1Trigger1.Setters.Add(player1Setter);

                var player1Trigger2 = new MultiDataTrigger();
                player1Trigger2.Conditions.Add(isSelfPlayerCondition);
                player1Trigger2.Conditions.Add(selfPlayerIsPlayer1);
                player1Trigger2.Setters.Add(player1Setter);

                var player2Trigger1 = new MultiDataTrigger();
                player2Trigger1.Conditions.Add(isOpponentCondition);
                player2Trigger1.Conditions.Add(opponentIsPlayer2);
                player2Trigger1.Setters.Add(player2Setter);

                var player2Trigger2 = new MultiDataTrigger();
                player2Trigger2.Conditions.Add(isSelfPlayerCondition);
                player2Trigger2.Conditions.Add(selfPlayerIsPlayer2);
                player2Trigger2.Setters.Add(player2Setter);

                var visibilitySetter  = new Setter(VisibilityProperty, Visibility.Visible);
                var visibilityTrigger = new DataTrigger
                {
                    Binding = new Binding("IsAlive")
                    {
                        Source = piece
                    },
                    Value = true
                };
                visibilityTrigger.Setters.Add(visibilitySetter);

                var onAttackFontSizeSetter = new Setter(FontSizeProperty, button.FontSize * 2);

                var winningForegroundSetter = new Setter(ForegroundProperty, Brushes.Green);
                var winningTrigger          = new DataTrigger
                {
                    Binding = new Binding("IsDefeating")
                    {
                        Source = piece
                    },
                    Value = true
                };
                winningTrigger.Setters.Add(onAttackFontSizeSetter);
                winningTrigger.Setters.Add(winningForegroundSetter);

                var defeatStoryboard = new Storyboard
                {
                    AccelerationRatio = 0.2
                };
                defeatStoryboard.Completed += (s, _) => DefeatStoryboard_Completed();
                var defeatAnimation = new DoubleAnimation(0.1, new TimeSpan(0, 0, 0, 2, 0));
                Storyboard.SetTarget(defeatAnimation, button);
                Storyboard.SetTargetProperty(defeatAnimation, new PropertyPath(FontSizeProperty));
                defeatStoryboard.Children.Add(defeatAnimation);
                var beginSb = new BeginStoryboard
                {
                    Storyboard = defeatStoryboard,
                    Name       = "DefeatStoryboard"
                };
                var stopSb = new StopStoryboard
                {
                    BeginStoryboardName = beginSb.Name
                };
                var losingForegroundSetter = new Setter(ForegroundProperty, Brushes.Red);
                var losingTrigger          = new DataTrigger
                {
                    Binding = new Binding("IsBeingDefeated")
                    {
                        Source = piece
                    },
                    Value = true
                };
                losingTrigger.EnterActions.Add(beginSb);
                losingTrigger.ExitActions.Add(stopSb);
                losingTrigger.Setters.Add(onAttackFontSizeSetter);
                losingTrigger.Setters.Add(losingForegroundSetter);

                buttonStyle.Triggers.Add(player1Trigger1);
                buttonStyle.Triggers.Add(player1Trigger2);
                buttonStyle.Triggers.Add(player2Trigger1);
                buttonStyle.Triggers.Add(player2Trigger2);
                buttonStyle.Triggers.Add(visibilityTrigger);
                buttonStyle.Triggers.Add(winningTrigger);
                buttonStyle.Triggers.Add(losingTrigger);

                buttonStyle.RegisterName(beginSb.Name, beginSb);
                button.Style = buttonStyle;

                ApplyBinding("Column", piece, button, Grid.ColumnProperty);
                ApplyBinding("Row", piece, button, Grid.RowProperty);
                ApplyBinding("PowerLevel", piece, button, ContentProperty);

                Panel.SetZIndex(button, 2);
                this.CombateGrid.Children.Add(button);
            }

            this.CombateGridChildren = this.CombateGrid.Children.Cast <UIElement>();

            base.OnApplyTemplate();
        }