By default, the DataContext
for your Button
is your UserControl DataContext
, not your UserControl, so you are trying to bind to DataContext.Command
instead of UserControl.Command
To bind to UserControl.Command
use the RelativeSource
binding
<Button Command="{Binding Command, RelativeSource={ RelativeSource AncestorType={x:Type local:MyControl}}}">
EDIT Just noticed the HB answer , which will also work. I usually prefer RelativeSource
bindings to ElementName
because sometimes I rename elements and use them to forget that other controls reference this element by name
source share