나는 control-A와 같은 명령에 대해 RoutedCommands를 가지고 있으며, 모두 잘 작동합니다. 그런 다음 4 개의 routed 명령을 추가하여 화살표 키를 사용하여 캔버스에서 개체를 왼쪽이나 오른쪽으로 움직였습니다. 때로는 작동하고 때로는 작동하지 않습니다. 처음에는 Canvas의 포커스 문제라고 생각했지만 동시에 컨트롤 A와 같은 다른 라우트 명령어는 작동하지만 화살키는 그렇지 않다는 것을 알았습니다. 여기에 무슨 일이 일어나고 있는지 전혀 알지 못합니다. 서로 다른 변수 이름을 가진 동일한 라우팅 된 명령입니다. 어떻게 100 %의 시간 동안 작동하고 하나는 50 %의 시간에만 작동합니까?WPF 라우팅 된 명령에서만 가끔 발생합니다.
작업 RoutedCommand :
_bindings.Add(new CommandBinding(DesignerCanvas.SelectAll, SelectAll_Executed));
SelectAll.InputGestures.Add(new KeyGesture(Key.A, ModifierKeys.Control));
private void SelectAll_Executed(object sender, ExecutedRoutedEventArgs e)
{
SelectionService.SelectAll();
}
오작동 RoutedCommand :
오작동 RoutedCommand는 그냥 다른 창을 연 다음, 캔버스에 다시가됩니다 와서 특히 후, 때로는 발사되지_bindings.Add(new CommandBinding(DesignerCanvas.MoveDown, MoveDown_Executed));
MoveDown.InputGestures.Add(new KeyGesture(Key.Down));
private void MoveDown_Executed(object sender, ExecutedRoutedEventArgs e)
{
e.Handled = true;
var selectedItems = from item in SelectionService.CurrentSelection.OfType<DesignerItem>()
select item;
if (selectedItems.Count() > 0)
{
for (int i = 0; i < selectedItems.Count(); i++)
selectedItems.ElementAt(i).Top += Option.OptionSingleton.Sensitivity;
}
}
다른 라우트 명령어가 영향을받지 않는 동안 발사를 중지합니다. 이 이상한 행동을 일으키는 아이디어가 있습니까? 이 바인딩 명령에 도달하기 전에에서 KeyDown이 처리되거나 CanExecute
이벤트가 도달하지 않을 수 있습니다 귀하의 경우
EventManager.RegisterClassHandler(typeof(FrameworkElement), CommandManager.CanExecuteEvent,
new CanExecuteRoutedEventHandler((s, e) => Debug.WriteLine("CanExecute: " + s)), true);
EventManager.RegisterClassHandler(typeof(FrameworkElement), CommandManager.ExecutedEvent,
new CanExecuteRoutedEventHandler((s, e) => Debug.WriteLine("Executed:" + s)), true);
EventManager.RegisterClassHandler(typeof(FrameworkElement), CommandManager.ExecutedEvent,
new CanExecuteRoutedEventHandler((s, e) => Debug.WriteLine("KeyDown:" + s)), true);
:
는 는