Msdn does not say InputBinding.Command or MouseBinding.Command is dependency property.
Some peoples use binding like <KeyBinding Command="{Binding MyCommand}" Key="N"/>
(Refer to link
It works fine. Other people says it works when put it in a controltemplate
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid SnapsToDevicePixels="true">
<Border x:Name="Bd" ...>
<DockPanel>
...
</DockPanel>
<Border.InputBindings>
<MouseBinding MouseAction="MiddleClick"
Command="{Binding CloseCommand}"/>
</Border.InputBindings>
</Border>
</Grid>
...
</ControlTemplate>
http://efreedom.com/Question/1-2660760/Defining-InputBindings-Within-Style
But
I tried your example and it works. But when I use it to a list(for example tabcontrol) and define a DataTemplate, code like
<DataTemplate x:Key="ClosableTabItemTemplate">
<DockPanel Width="120">
<DockPanel.InputBindings>
<KeyBinding Command="{Binding Path=CloseCommand}" Key="N"/>
</DockPanel.InputBindings>
<Button
Command="{Binding Path=CloseCommand}"
Content="X"
Cursor="Hand"
DockPanel.Dock="Right"
Focusable="False"
FontFamily="Courier"
FontSize="9"
FontWeight="Bold"
Margin="0,1,0,0"
Padding="0"
VerticalContentAlignment="Bottom"
Width="16" Height="16"
/>
</DockPanel>
</DataTemplate>
I always throw an exception "A 'Binding' cannot be set on the 'Command' property of type 'MouseBinding'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject."
My code works if I remove <DockPanel.InputBindings> section.
Thanks.
Rulin Hong