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 needs to pass "{Binding Name}" as an argument.
How would I do this? I'm developing for Windows Phone 7.
An alternative on the pc is to get get the DataContext from the click event args e.g.
private void Button_Click(object sender, RoutedEventArgs e)
{
var record = ((Button)e.OriginalSource).DataContext;
MessageBox.Show("Do something with " + record.ToString());
}
this might be applicable to the phone as well?
I think you need to use a command instead of a button click event to do this so you can do:
<Button Name="btnJeans" Command="{Binding Path=ButtonClickCommand}" CommandParameter="{Binding Name}">
...
</Button>
You'll then need to expose ButtonClickCommand as a ICommand object.
How to do this will depend on the structure of the rest of your application. E.g. Using MVVM pattern etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With