tags:

views:

28

answers:

1

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.

+1  A: 

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.

Andy Lowry
The property 'Command' was not found in type 'Button'. The same goes for the Parameters
Tim van Dalen
That's odd. I just put your code into a simple WPF window, and I could add the Command and CommandParameter properties to Button. Looking at MSDN they seem to be there for Silverlight as well, so that can't be the problem.
Andy Lowry
Here is the MSDN page: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.buttonbase.command(v=VS.100).aspx
Andy Lowry
I should probably mention that I'm developing for the Windows Phone 7 platform
Tim van Dalen
Apparently Command is supported in SL4... but not on WP7 :( (http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.buttonbase.command%28v=VS.95%29.aspx)
Thomas Levesque
Then, would there be another way to do this?
Tim van Dalen
I've never used WP7, so I don't know the best solution. I know there are a number of libraries (MVVM Light, Caliburn.Micro?) which are designed to work around some of the missing bits. Maybe these can provide a solution for you.
Andy Lowry
Ok, thanks anyway. Those libs don't really give that functionality so I'll wait for another answer.
Tim van Dalen