zoukankan      html  css  js  c++  java
  • WPF Popup MenuDropAlignment 系统菜单弹出框方向问题

    右键菜单,tootip等弹出时,弹出的位置经常在左侧,使用体验不好。

    弹出方向有左对齐和右对齐 SystemParameters.MenuDropAlignment

    当右对齐时,值为false

    可以在控制面板中查看当前的设置:

     如何在软件中强制向右弹出显示?

    可以设置SystemParameters.MenuDropAlignment值,因为没有公开属性的set方法,只能用反射去修改了。

    public static class MenuDropAlignmentHelper
        {
            private static FieldInfo _menuDropAlignmentField;
            public static void DisableSystemMenuAlignment()
            {
                _menuDropAlignmentField = typeof(SystemParameters).GetField("_menuDropAlignment", BindingFlags.NonPublic | BindingFlags.Static);
    
                EnsureStandardPopupAlignment();
                SystemParameters.StaticPropertyChanged -= SystemParameters_StaticPropertyChanged;
                SystemParameters.StaticPropertyChanged += SystemParameters_StaticPropertyChanged;
            }
    
            private static void SystemParameters_StaticPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                EnsureStandardPopupAlignment();
            }
    
            private static void EnsureStandardPopupAlignment()
            {
                if (SystemParameters.MenuDropAlignment)
                {
                    _menuDropAlignmentField?.SetValue(null, false);
                }
            }
        }

    之后在相应的窗口下,调用此方法MenuDropAlignmentHelper.DisableSystemMenuAlignment即可。

    参考文章:

    https://stackoverflow.com/questions/18113597/wpf-handedness-with-popups

    来自:https://www.cnblogs.com/kybs0/p/13555206.html

  • 相关阅读:
    85个国外Ajax例子
    如何捕获方向键
    C#版对对碰[强荐]
    如何关闭移动盘的自动播放
    常用算法大全-回溯算法
    string转换成color
    常用算法大全-分而治之算法
    常用算法大全-分枝定界
    C#游戏——极品蜜蜂V1.0
    WebService传多个参数和返回多个参数的方法
  • 原文地址:https://www.cnblogs.com/ilison/p/13815217.html
Copyright © 2011-2022 走看看