//для текущей ячейки когда в ней фокус рисуется прозрачный фон //а для подсвеченных ячеек должен рисоваться не смешанный фон private static void AddFocusedTrigger(Style style, string name, object value, SolidColorBrush normalBrush) { var trigger = new MultiDataTrigger { Conditions = { new Condition(new Binding(name), value), new Condition(new Binding("(IsFocused)") { RelativeSource = RelativeSource.Self }, true), new Condition(new Binding("(IsSelected)") { RelativeSource = RelativeSource.Self }, true), new Condition( new Binding("(Selector.IsSelectionActive)") { RelativeSource = RelativeSource.Self }, true), }, Setters = { new Setter(Control.BackgroundProperty, normalBrush), new Setter(Control.BorderBrushProperty, normalBrush) } }; style.Triggers.Add(trigger); }
DataTemplate CreateItemTemplate() { var template = new DataTemplate(); template.VisualTree = new FrameworkElementFactory(typeof(StackPanel)); var txtBlock = new FrameworkElementFactory(typeof(TextBlock)); txtBlock.SetBinding(TextBlock.TextProperty, new Binding("Street1")); template.VisualTree.AppendChild(txtBlock); txtBlock = new FrameworkElementFactory(typeof(TextBlock)); txtBlock.SetBinding(TextBlock.TextProperty, new Binding("City")); template.VisualTree.AppendChild(txtBlock); var trigger = new MultiDataTrigger(); trigger.Conditions.Add( new Condition( new Binding("Cty"), //misspelling "Tallahassee" ) ); trigger.Conditions.Add( new Condition( new Binding("StateOrProvince"), "Florida" ) ); template.Triggers.Add(trigger); return(template); }
public void AddTabButton(string name) { // Code for buttons linking to other tabs Button gotoTab_Button = new Button(); gotoTab_Button.Content = name; gotoTab_Button.Tag = name; gotoTab_Button.Background = new SolidColorBrush(Colors.LightGray); gotoTab_Button.BorderBrush = new SolidColorBrush(Colors.Transparent); Style customButtonStyle = new Style(); customButtonStyle.TargetType = typeof(Button); MultiDataTrigger trigger = new MultiDataTrigger(); Condition condition = new Condition(); condition.Binding = new Binding() { Path = new PropertyPath("IsMouseOver"), RelativeSource = RelativeSource.Self }; condition.Value = true; Setter foregroundSetter = new Setter(); foregroundSetter.Property = Button.ForegroundProperty; foregroundSetter.Value = Brushes.DarkOrange; Setter cursorSetter = new Setter(); cursorSetter.Property = Button.CursorProperty; cursorSetter.Value = Cursors.Hand; Setter textSetter = new Setter(); textSetter.Property = Button.FontWeightProperty; textSetter.Value = FontWeights.ExtraBold; trigger.Conditions.Add(condition); trigger.Setters.Add(foregroundSetter); trigger.Setters.Add(cursorSetter); trigger.Setters.Add(textSetter); customButtonStyle.Triggers.Clear(); customButtonStyle.Triggers.Add(trigger); gotoTab_Button.Style = customButtonStyle; gotoTab_Button.Click += mainWindowCaller.gotoTabButton_Click; Grid.SetRow(gotoTab_Button, 0); Grid.SetColumn(gotoTab_Button, 1); this.Children.Add(gotoTab_Button); }
private MultiDataTrigger GenMouseOverTrigger() { MultiDataTrigger trigger = new MultiDataTrigger(); Condition condition = new Condition(); condition.Binding = new Binding() { Path = new PropertyPath("IsMouseOver"), RelativeSource = RelativeSource.Self }; condition.Value = true; Setter setter = new Setter(); setter.Property = BackgroundProperty; setter.Value = new SolidColorBrush(Resource.borderColor); trigger.Conditions.Add(condition); trigger.Setters.Add(setter); return(trigger); }
private static void AddBackgroundTriggers(Style style, string name, bool value, Brush brush) { var trigger = new MultiDataTrigger { Conditions = { new Condition(new Binding(name), value), new Condition(new Binding("(IsSelected)") { RelativeSource = RelativeSource.Self }, false) }, Setters = { new Setter(Control.BackgroundProperty, brush), new Setter(Control.BorderBrushProperty, brush) } }; style.Triggers.Add(trigger); }
public void MultiDataTriggerBasicTest() { Condition condition1 = new Condition { Binding = new Binding { Path = PropertyPath.Parse("X") }, Value = 1 }; Condition condition2 = new Condition { Binding = new Binding { Path = PropertyPath.Parse("Y") }, Value = 2 }; MultiDataTrigger multiDataTrigger = new MultiDataTrigger(); multiDataTrigger.Conditions.Add(condition1); multiDataTrigger.Conditions.Add(condition2); multiDataTrigger.Setters.Add(new Setter { Property = new DependencyPropertyPathElement(Value1Property), Value = 1 }); FrameworkElement element = new FrameworkElement(); element.DataContext = new Point(1, 2); Assert.AreEqual(0, element.GetValue(Value1Property)); element.Triggers.Add(multiDataTrigger); Assert.AreEqual(1, element.GetValue(Value1Property)); element.DataContext = Point.Zero; Assert.AreEqual(0, element.GetValue(Value1Property)); element.DataContext = new Point(1, 2); Assert.AreEqual(1, element.GetValue(Value1Property)); element.Triggers.Remove(multiDataTrigger); Assert.AreEqual(0, element.GetValue(Value1Property)); }
protected override void OverrideItemContainerStyle(Style style) { if (style == null) { throw new ArgumentNullException(nameof(style)); } var showHiddenTrigger = new MultiDataTrigger(); showHiddenTrigger.Conditions.Add(new Condition(new Binding(nameof(ShowHidden)) { Source = this }, false)); showHiddenTrigger.Conditions.Add(new Condition(new Binding(nameof(FileSystemNodeViewModel.IsHidden)), true)); showHiddenTrigger.Setters.Add(new Setter(UIElement.VisibilityProperty, Visibility.Collapsed)); style.Triggers.Add(showHiddenTrigger); var showSystemTrigger = new MultiDataTrigger(); showSystemTrigger.Conditions.Add(new Condition(new Binding(nameof(ShowSystem)) { Source = this }, false)); showSystemTrigger.Conditions.Add(new Condition(new Binding(nameof(FileSystemNodeViewModel.IsSystem)), true)); showSystemTrigger.Setters.Add(new Setter(UIElement.VisibilityProperty, Visibility.Collapsed)); style.Triggers.Add(showSystemTrigger); var showFilesTrigger = new MultiDataTrigger(); showFilesTrigger.Conditions.Add(new Condition(new Binding(nameof(ShowFiles)) { Source = this }, false)); showFilesTrigger.Conditions.Add(new Condition(new Binding(nameof(FileSystemNodeViewModel.IsFile)), true)); showFilesTrigger.Setters.Add(new Setter(UIElement.VisibilityProperty, Visibility.Collapsed)); style.Triggers.Add(showFilesTrigger); }
public InputXMLWindow() { InitializeComponent(); #region Button Code NewXML_Button.Background = new SolidColorBrush(Colors.LightGray); NewXML_Button.BorderBrush = new SolidColorBrush(Colors.Transparent); ChooseXMLButton.Background = new SolidColorBrush(Colors.LightGray); ChooseXMLButton.BorderBrush = new SolidColorBrush(Colors.Transparent); Style customButtonStyle = new Style(); customButtonStyle.TargetType = typeof(Button); MultiDataTrigger trigger = new MultiDataTrigger(); Condition condition = new Condition(); condition.Binding = new Binding() { Path = new PropertyPath("IsMouseOver"), RelativeSource = RelativeSource.Self }; condition.Value = true; Setter foregroundSetter = new Setter(); foregroundSetter.Property = Button.ForegroundProperty; foregroundSetter.Value = Brushes.DarkOrange; Setter cursorSetter = new Setter(); cursorSetter.Property = Button.CursorProperty; cursorSetter.Value = Cursors.Hand; Setter textSetter = new Setter(); textSetter.Property = Button.FontWeightProperty; textSetter.Value = FontWeights.ExtraBold; trigger.Conditions.Add(condition); trigger.Setters.Add(foregroundSetter); trigger.Setters.Add(cursorSetter); trigger.Setters.Add(textSetter); customButtonStyle.Triggers.Clear(); customButtonStyle.Triggers.Add(trigger); NewXML_Button.Style = customButtonStyle; ChooseXMLButton.Style = customButtonStyle; #endregion }
Style CreateStyle() { var style = new Style(); var trigger = new MultiDataTrigger(); trigger.Conditions.Add( new Condition( new Binding("Cty"), //misspelling "Tallahassee" ) ); trigger.Conditions.Add( new Condition( new Binding("Age"), 21 ) ); style.Triggers.Add(trigger); return(style); }
public void GenerateSetters() { var triggerBinding = new Binding { Converter = new ExpressionConverter(), ConverterParameter = Parent.ConvertToFields(ExpressionString), Path = ApplyToRow ? new PropertyPath("Row") : new PropertyPath("RowData.Row") }; //StyleTrigger = new DataTrigger { Value = true, Binding = triggerBinding }; StyleTrigger = new MultiDataTrigger(); StyleTrigger.Conditions.Add(new Condition { Binding = triggerBinding, Value = true }); StyleTrigger.Conditions.Add(new Condition { Binding = new Binding("SelectionState"), Value = SelectionState.None }); if (Foreground != null) { StyleTrigger.Setters.Add(new Setter(Control.ForegroundProperty, new Binding("Foreground") { Source = this })); } if (Background != null) { const string backgroundPropertyName = "Background"; StyleTrigger.Setters.Add(new Setter(Control.BackgroundProperty, new Binding(backgroundPropertyName) { Source = this })); StyleTrigger.Setters.Add(new Setter(LightweightCellEditor.BackgroundProperty, new Binding(backgroundPropertyName) { Source = this })); } if (FontFamily != null) { StyleTrigger.Setters.Add(new Setter(Control.FontFamilyProperty, new Binding("FontFamily") { Source = this })); } if (FontStyle.HasValue) { StyleTrigger.Setters.Add(new Setter(Control.FontStyleProperty, new Binding("FontStyle") { Source = this })); } if (FontSize > 0) { StyleTrigger.Setters.Add(new Setter(Control.FontSizeProperty, new Binding("FontSize") { Source = this })); } if (FontWeight.HasValue) { StyleTrigger.Setters.Add(new Setter(Control.FontWeightProperty, new Binding("FontWeight") { Source = this })); } }
public MultiDataTriggerItem(MultiDataTrigger trigger, FrameworkElement source, TriggerSource triggerSource) : base(source, TriggerType.MultiDataTrigger, triggerSource) { _trigger = trigger; _source = source; }
public MultiDataTriggerItem(MultiDataTrigger trigger, FrameworkElement source, TriggerSource triggerSource) : base(trigger, source, TriggerType.MultiDataTrigger, triggerSource) { this.trigger = trigger; this.source = source; }
public static void AddEditableTriggers(Style style, string name, object value, Color baseColor, Color active, Color inactive) { var color = baseColor; var normalBrush = new SolidColorBrush(color); var activeBrush = new SolidColorBrush(Mix(color, active, 0.6f)); var inactiveBrush = new SolidColorBrush(Mix(color, inactive, 0.6f)); var trigger = new MultiDataTrigger { Conditions = { new Condition(new Binding(name), value), new Condition(new Binding("(IsSelected)") { RelativeSource = RelativeSource.Self }, false) }, Setters = { new Setter(Control.BackgroundProperty, normalBrush), new Setter(Control.BorderBrushProperty, normalBrush) } }; style.Triggers.Add(trigger); trigger = new MultiDataTrigger { Conditions = { new Condition(new Binding(name), value), new Condition(new Binding("(IsSelected)") { RelativeSource = RelativeSource.Self }, true), new Condition( new Binding("(Selector.IsSelectionActive)") { RelativeSource = RelativeSource.Self }, true), }, Setters = { new Setter(Control.BackgroundProperty, activeBrush), new Setter(Control.BorderBrushProperty, activeBrush) } }; style.Triggers.Add(trigger); trigger = new MultiDataTrigger { Conditions = { new Condition(new Binding(name), value), new Condition(new Binding("(IsSelected)") { RelativeSource = RelativeSource.Self }, true), new Condition( new Binding("(Selector.IsSelectionActive)") { RelativeSource = RelativeSource.Self }, false), }, Setters = { new Setter(Control.BackgroundProperty, inactiveBrush), new Setter(Control.BorderBrushProperty, inactiveBrush) } }; style.Triggers.Add(trigger); }
public PreviewAdorner(UIElement adornedElement, IResourcesManager resourcesManager, IVsSettings vsSettings) : base(adornedElement) { //content var panel = new StackPanel() { Orientation = Orientation.Vertical, Margin = new Thickness(6, 6, 8, 8), UseLayoutRounding = true, SnapsToDevicePixels = true }; var image = new Image() { SnapsToDevicePixels = true, UseLayoutRounding = true }; RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.NearestNeighbor); image.SetBinding(Image.SourceProperty, new Binding(nameof(TeXCommentAdornment.RenderedImage)) { Source = adornedElement }); image.SetBinding(Image.WidthProperty, new Binding(nameof(TeXCommentAdornment.RenderedImageWidth)) { Source = adornedElement }); image.SetBinding(Image.HeightProperty, new Binding(nameof(TeXCommentAdornment.RenderedImageHeight)) { Source = adornedElement }); //var style = new Style(typeof(Image)); //var grayscaleTrigger = new DataTrigger() //{ // Binding = new Binding(nameof(TeXCommentAdornment.CurrentState)) { Source = adornedElement }, // Value = TeXCommentAdornmentState.EditingAndRenderingPreview //}; //grayscaleTrigger.Setters.Add(new Setter(Image.EffectProperty, graycaleEffect)); //style.Triggers.Add(grayscaleTrigger); //image.Style = style; var textBlock = new TextBlock() { Text = "Preview:", Margin = new Thickness(0, 0, 0, 2) }; textBlock.SetBinding(TextBlock.ForegroundProperty, new Binding(nameof(IResourcesManager.ForegroundUI)) { Source = resourcesManager }); panel.Children.Add(textBlock); panel.Children.Add(image); var border = new Border() { BorderThickness = new Thickness(1), Child = panel }; border.SetBinding(Border.BorderBrushProperty, new Binding(nameof(IResourcesManager.ForegroundUI)) { Source = resourcesManager }); border.SetBinding(Border.BackgroundProperty, new Binding(nameof(IVsSettings.CommentsBackground)) { Source = vsSettings }); Child = border; //visibility setup var style = new Style(typeof(PreviewAdorner)); style.Setters.Add(new Setter(VisibilityProperty, Visibility.Collapsed)); var visibilityTrigger = new MultiDataTrigger(); visibilityTrigger.Conditions.Add(new Condition(new Binding(nameof(TeXCommentAdornment.CurrentState)) { Source = adornedElement }, TeXCommentAdornmentState.EditingWithPreview)); visibilityTrigger.Conditions.Add(new Condition(new Binding(nameof(TeXCommentAdornment.IsCaretInsideTeXBlock)) { Source = adornedElement }, true)); visibilityTrigger.Setters.Add(new Setter(VisibilityProperty, Visibility.Visible)); style.Triggers.Add(visibilityTrigger); visibilityTrigger = new MultiDataTrigger(); visibilityTrigger.Conditions.Add(new Condition(new Binding(nameof(TeXCommentAdornment.CurrentState)) { Source = adornedElement }, TeXCommentAdornmentState.EditingAndRenderingPreview)); visibilityTrigger.Conditions.Add(new Condition(new Binding(nameof(TeXCommentAdornment.IsCaretInsideTeXBlock)) { Source = adornedElement }, true)); visibilityTrigger.Setters.Add(new Setter(VisibilityProperty, Visibility.Visible)); style.Triggers.Add(visibilityTrigger); Style = style; }
public MultiDataTriggerItem(MultiDataTrigger trigger, DependencyObject source, TriggerSource triggerSource) : base(trigger, source, TriggerType.MultiDataTrigger, triggerSource) { this.trigger = trigger; this.source = source; }
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(); }