Skip to content

Commit

Permalink
Updating the command parameter binding for the ColorCommand property …
Browse files Browse the repository at this point in the history
…so that it works properly and isn't always passing null.
  • Loading branch information
Scott Meddows committed Dec 12, 2023
1 parent b66c1ee commit 0ae5079
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Grid Grid.Column="0" Margin="0,0,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
Expand All @@ -35,7 +35,7 @@
<Button x:Name="button" Content="Click Me" HorizontalAlignment="Stretch" Grid.Row="1" Margin="0,10,0,10">
<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>
</Button>
Expand All @@ -48,7 +48,7 @@
</TextBlock>
<TextBlock TextWrapping="Wrap" Margin="10,20,0,0" FontSize="15" Foreground="DeepPink" xml:space="preserve">&lt;Behaviors:Interaction.Triggers>
&lt;Behaviors:EventTrigger EventName="Click" SourceObject="{Binding ElementName=button}">
&lt;Behaviors:InvokeCommandAction Command="{Binding ColorCommand}" CommandParameter="{Binding Grid.Background}" />
&lt;Behaviors:InvokeCommandAction Command="{Binding ColorCommand}" CommandParameter="{Binding Background, ElementName=Grid}" />
&lt;/Behaviors:EventTrigger>
&lt;/Behaviors:Interaction.Triggers>
</TextBlock>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0ae5079

Please sign in to comment.