Исключение в RibbonGallery, когда значение dpi Windows составляет 125% или больше
Я использую RibbonGallery в своем приложении WPF.
<r:RibbonGallery ItemsSource="{Binding MenuBar}"
Style="{StaticResource GalleryStyle}">
</r:RibbonGallery>
ViewModel:
public ObservableCollection<MenuCategoryModel> MenuBar { get; set; }
Когда я открываю RibbonGallery и щелкаю один из элементов RibbonGalleryIte, открывается необходимый экран, и RibbonGallery автоматически закрывается. Но если этот конкретный экран уже открыт, и я снова щелкаю тот же RibbonGalleryItem, RibbonGallery останется открытым.
Чтобы вручную закрыть RibbonGallery, я сбросил значение ItemSource of RibbonGallery следующим образом:
var tempMenuBar = MenuBar;
MenuBar = null;
OnPropertyChanged("MenuBar");
MenuBar = tempMenuBar;
OnPropertyChanged("MenuBar");
Это успешно закрывает RibbonGallery, но когда значение dpi Windows установлено на 125%, и тот же самый элемент RibbonGalleryItem (чей экран уже находится в фокусе), я получаю следующее исключение:
Значение не может быть NULL. Имя_параметра: menuSite в PresentationCore
Это трассировка стека:
at System.Windows.Input.InputManager.PushMenuMode(PresentationSource menuSite)
at System.Windows.Controls.Primitives.MenuBase.PushMenuMode(Boolean isAcquireFocusMenuMode)
at System.Windows.Controls.Primitives.MenuBase.OnPreviewKeyboardInputProviderAcquireFocus(Object sender, KeyboardInputProviderAcquireFocusEventArgs e)
at System.Windows.Input.KeyboardInputProviderAcquireFocusEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
at System.Windows.UIElement.Focus()
at Microsoft.Windows.Controls.Ribbon.RibbonGalleryItem.OnMouseMove(MouseEventArgs e)
at System.Windows.UIElement.OnMouseMoveThunk(Object sender, MouseEventArgs e)
at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.MouseDevice.Synchronize()
at System.Windows.Input.MouseDevice.ChangeMouseCapture(IInputElement mouseCapture, IMouseInputProvider providerCapture, CaptureMode captureMode, Int32 timestamp)
at System.Windows.Input.MouseDevice.PreNotifyInput(Object sender, NotifyInputEventArgs e)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Эта проблема возникает, только если значение dpi Windows составляет 125% или более.
Кроме того, это не может быть воспроизведено в режиме отладки.
Любые идеи о том, что является реальной причиной этого исключения и какие-либо предложения о том, как это исправить?