XAML Arguments for Click Event

I have the following XAML:

<Button Name="btnJeans" Click="btnJeans_Click" Padding="-1" > <StackPanel Orientation="Horizontal" Margin="0,0,0,17" Name="jeansItem"> <!--Replace rectangle with image--> <Image Height="119" Width="82" Source="{Binding Image}" Margin="12,0,9,0"/> <StackPanel Width="311"> <TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/> <TextBlock Text="{Binding Price}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/> </StackPanel> </StackPanel> </Button> 

However, btnJeans_Click must pass "{Binding Name}" as an argument.

How can I do it? I am developing for Windows Phone 7.

+4
source share
2 answers

An alternative on a PC is to get GetConttext from click event events, for example.

 private void Button_Click(object sender, RoutedEventArgs e) { var record = ((Button)e.OriginalSource).DataContext; MessageBox.Show("Do something with " + record.ToString()); } 

Can this also apply to the phone?

+5
source

I think you need to use the command instead of the button click event to do this so you can:

 <Button Name="btnJeans" Command="{Binding Path=ButtonClickCommand}" CommandParameter="{Binding Name}"> ... </Button> 

Then you will need to open ButtonClickCommand as an ICommand object.

How to do this will depend on the structure of the rest of your application. For instance. Using MVVM template etc.

+3
source

All Articles