views:

245

answers:

2

I want to pass the current DataContext (which is an instance of a ViewModel) as a CommandParameter on a WPF Button. What would be the syntax I should use?

<Button 
  x:Name="btnMain"
  Command="infra:ApplicationCommands.MyCommand"
  CommandParameter="{Binding ???}"
 />
+6  A: 

An empty Binding, without a path, binds directly to the DataContext, so

{Binding}

is enough to make it work! Your example:

<Button 
  x:Name="btnMain"
  Command="infra:ApplicationCommands.MyCommand"
  CommandParameter="{Binding}"
 />
Arcturus
+1 beat me to it!
masenkablast
heh, as simple as that, thanks!
devdigital
+2  A: 
<Button 
   x:Name="btnMain"
   Command="infra:ApplicationCommands.MyCommand"
   CommandParameter="{Binding}" 
/>

as long as the button is within the Visual tree of the item with the DataContext

masenkablast