我有TreeView
以下定义:
<TreeView ItemsSource="{Binding Folders, UpdateSourceTrigger=PropertyChanged}" x:Name="tree">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Folders, UpdateSourceTrigger=PropertyChanged}">
<Label Content="{Binding Name}" >
<Label.InputBindings>
<KeyBinding Key="Delete"
Command="{Binding DataContext.DeleteFolderCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"/>
<MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding DataContext.SelectFolderCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}}"
CommandParameter="{Binding ElementName=tree, Path=SelectedItem}" />
</Label.InputBindings>
</Label>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
此视图与它的代码隐藏文件有关:
DataContext="{Binding RelativeSource={RelativeSource Self}}"
只是工作InputBinding
正常。LeftDoubleClick
但是InputBinding
“删除”键不起作用。
绑定到的Command
地方如下所示:KeyBinding
public ICommand DeleteFolderCommand
{
get { return _deleteFolderCommand; }
set
{
_deleteFolderCommand = value;
OnPropertyChanged();
}
}
在构造函数中我定义:
DeleteFolderCommand = new RelayCommand(DeleteFolder);
DeleteFolder-Method 看起来像:
private void DeleteFolder(object parameter)
{
// Break-Point here will not be reached
}
我究竟做错了什么?
我已经检查了输出窗口的绑定错误,但没有。