From 0ae507945a908a09fb221c5567b7b0d4d19fc450 Mon Sep 17 00:00:00 2001 From: Scott Meddows Date: Tue, 12 Dec 2023 11:41:33 -0800 Subject: [PATCH] Updating the command parameter binding for the ColorCommand property so that it works properly and isn't always passing null. --- .../XAMLBehaviorsSample/InvokeCommandControl.xaml | 6 +++--- .../XAMLBehaviorsSample/InvokeCommandControl.xaml.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/XAMLBehaviorsSample/XAMLBehaviorsSample/InvokeCommandControl.xaml b/samples/XAMLBehaviorsSample/XAMLBehaviorsSample/InvokeCommandControl.xaml index 15dcbde..a6d6a25 100644 --- a/samples/XAMLBehaviorsSample/XAMLBehaviorsSample/InvokeCommandControl.xaml +++ b/samples/XAMLBehaviorsSample/XAMLBehaviorsSample/InvokeCommandControl.xaml @@ -24,7 +24,7 @@ - + @@ -35,7 +35,7 @@ @@ -48,7 +48,7 @@ <Behaviors:Interaction.Triggers> <Behaviors:EventTrigger EventName="Click" SourceObject="{Binding ElementName=button}"> - <Behaviors:InvokeCommandAction Command="{Binding ColorCommand}" CommandParameter="{Binding Grid.Background}" /> + <Behaviors:InvokeCommandAction Command="{Binding ColorCommand}" CommandParameter="{Binding Background, ElementName=Grid}" /> </Behaviors:EventTrigger> </Behaviors:Interaction.Triggers> diff --git a/samples/XAMLBehaviorsSample/XAMLBehaviorsSample/InvokeCommandControl.xaml.cs b/samples/XAMLBehaviorsSample/XAMLBehaviorsSample/InvokeCommandControl.xaml.cs index b6ea742..af8eb8f 100644 --- a/samples/XAMLBehaviorsSample/XAMLBehaviorsSample/InvokeCommandControl.xaml.cs +++ b/samples/XAMLBehaviorsSample/XAMLBehaviorsSample/InvokeCommandControl.xaml.cs @@ -40,12 +40,12 @@ public bool CanExecute(object parameter) public void Execute(object parameter) { - Brush currentBackground = this.control.Grid.Background; + Brush currentBackground = (Brush)parameter; + if (currentBackground != Brushes.DarkBlue) { this.control.Grid.Background = Brushes.DarkBlue; - } - else + } else { this.control.Grid.Background = Brushes.DeepPink; }