Краткая версия
Звонки на CommandManager.InvalidateRequerySuggested()
занимают гораздо больше времени, чем я хотел бы (задержка на 1-2 секунды до отключения элементов управления пользовательского интерфейса).
Длинная версия
У меня есть система, где я отправляю задачи на фоновый поток на основе процессора задач. Этот запрос выполняется в потоке пользовательского интерфейса WPF.
Когда этот запрос выполняется, объект, который управляет моим фоновым потоком, выполняет две вещи:
-
Он вызывает событие "занято" (все еще в потоке пользовательского интерфейса), на которое реагируют несколько моделей просмотров; когда они получают это событие, они устанавливают флаг
IsEnabled
на себяfalse
. Элементы управления в моих представлениях, которые привязаны к этому свойству, немедленно отображаются серым цветом, что я и ожидал. -
Он сообщает моим WPF
ICommand
объектам, что их нельзя разрешать (опять же, по-прежнему в потоке пользовательского интерфейса). Поскольку нет объектовINotifyPropertyChanged
дляICommand
, я вынужден вызватьCommandManager.InvalidateRequerySuggested()
, чтобы заставить WPF пересмотреть все состояния моих команд <CanExecute
(да, мне действительно нужно это сделать: в противном случае, ни один из этих элементов управления не отключается). Однако, в отличие от пункта 1, для моих кнопок/пунктов меню /etc, использующих объектыICommand
, требуется значительно больше времени, чтобы визуально перейти в отключенное состояние, чем для элементов управления пользовательского интерфейса, для которых установлено свойствоIsEnabled
вручную.
Проблема заключается в том, что с точки зрения UX это выглядит ужасно; половина моих элементов управления сразу же отображается серым цветом (потому что для их свойства IsEnabled
установлено значение false), а затем через полторы секунды спустя другая половина моих элементов управления подходит к примеру (потому что их методы CanExecute
оценивали).
Итак, часть 1 моего вопроса:
Как глупо, как кажется, чтобы спросить, есть ли способ сделать CommandManager.InvalidateRequerySuggested()
сделать это быстрее? Я подозреваю, что нет.
Достаточно справедливо, часть 2 моего вопроса:
Как я могу обойти это? Я бы предпочел, чтобы все мои элементы управления были отключены одновременно. В противном случае это выглядит непрофессионально и неудобно. Есть идеи?: -)