2

我在我的 WPF 应用程序中使用RibbonGallery 。

<r:RibbonGallery ItemsSource="{Binding MenuBar}"
             Style="{StaticResource GalleryStyle}">
</r:RibbonGallery> 

视图模型:

public ObservableCollection<MenuCategoryModel> MenuBar { get; set; }

当我打开 RibbonGallery 并单击其中一个 RibbonGalleryItem 时,将打开所需的屏幕,并自动关闭 RibbonGallery。但是,如果该特定屏幕已经打开,并且我再次单击相同的 RibbonGalleryItem,RibbonGallery 将保持打开状态。

要手动关闭 RibbonGallery,我重置了 RibbonGallery 的 ItemSource 的值,如下所示:

var tempMenuBar = MenuBar;
MenuBar = null;                                                                                         
OnPropertyChanged("MenuBar");
MenuBar = tempMenuBar;
OnPropertyChanged("MenuBar");

这成功关闭了 RibbonGallery,但是当 Windows dpi 值设置为 125%,并且单击了相同的 RibbonGalleryItem(其屏幕已经处于焦点)时,我得到以下异常:

值不能为 NULL。参数名称:PresentationCore 中的 menuSite

这是堆栈跟踪:

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)

仅当 Windows dpi 值为 125% 或更高时才会出现此问题。

此外,这无法在调试模式下重现。

有关此异常的实际原因的任何想法以及有关如何解决此问题的任何建议?

4

0 回答 0