Use DataContext as CommandParameter in WPF Use DataContext as CommandParameter in WPF wpf wpf

Use DataContext as CommandParameter in WPF


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}" />


<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