当Windows dpi值为125%或更高时,RibbonGallery中的异常

时间:2017-03-08 07:14:44

标签: c# wpf dpi ribbon-control ribboncontrolslibrary

我在WPF应用程序中使用 RibbonGallery

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

视图模型:

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

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

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

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

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

值不能为NULL。 Parametername: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%或更高时才会出现此问题。

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

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

0 个答案:

没有答案