Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use DataContext as CommandParameter in WPF

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 ???}"  /> 
like image 766
devdigital Avatar asked Feb 23 '10 16:02

devdigital


1 Answers

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}"  /> 
like image 72
Arcturus Avatar answered Oct 08 '22 20:10

Arcturus