不能将SHIFT + Delete KeyGesture分配给WPF中的DevExpress条项。对此有任何限制,还是我做错了?
<dxb:BarButtonItem
x:Name="btnDelete"
Command="{Binding BtnDelete_Command}"
CommandParameter="{Binding ElementName=view}"
KeyGesture="SHIFT+Delete"
Content="Delete" />
答案 0 :(得分:3)
这是我尝试过的代码:
<dxb:BarManager>
<dxb:BarManager.Items>
<dxb:BarButtonItem x:Name="btnDelete" Command="{Binding BtnDelete_Command}" CommandParameter="{Binding ElementName=view}" KeyGesture="SHIFT+Delete" Content="Delete" />
</dxb:BarManager.Items>
<dxb:BarManager.Bars>
<dxb:Bar>
<dxb:Bar.ItemLinks>
<dxb:BarButtonItemLink BarItemName="btnDelete"/>
</dxb:Bar.ItemLinks>
</dxb:Bar>
</dxb:BarManager.Bars>
<StackPanel>
<Button Content="sdgsdg" />
<TextBox x:Name="view"/>
</StackPanel>
</dxb:BarManager>
public partial class MainWindow : Window {
public ICommand BtnDelete_Command { get; set; }
public MainWindow() {
BtnDelete_Command = new MyCommand();
DataContext = this;
InitializeComponent();
}
}
public class MyCommand : ICommand {
public bool CanExecute(object parameter) {
return true;
}
public event EventHandler CanExecuteChanged {
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
public void Execute(object parameter) {
MessageBox.Show(parameter.GetType().ToString());
}
}
这里运作正常。如果编辑器未聚焦,则执行该命令。如果编辑器是聚焦的,它自己处理这个键组合,因此不执行命令。