问题描述参考 html
当开发完程序后,咱们在多操做系统测试时候发现:win8.0 系统中 popup 弹出的位置总是不对。windows
以下图:函数
WinXp /Vista/Win7/Win8.1 下面windows 右键菜单弹出的位置(红色圈为 鼠标指针位置)post
Win8.0 下面windows 右键菜单弹出的位置(红色圈为 鼠标指针位置)测试
Popup 控件也是这个状况。须要在代码里面判断windows的版本。若是是win8.0 popup 的HorizontalOffset、VerticalOffset值须要调整。url
解决方案一。。经过注册表来获取当前系统版本操作系统
由于 Environment.OSVersion.Version 获取到的win8.0跟win8.1信息是同样的。3d
经过注册表获取win8.0代码为6.2 ,win8.1代码为6.3指针
public static string SetRegister() { string regpath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; RegistryKey uaes = Registry.LocalMachine.OpenSubKey(regpath, RegistryKeyPermissionCheck.ReadWriteSubTree, System.Security.AccessControl.RegistryRights.FullControl); if (uaes == null) uaes = Registry.LocalMachine.CreateSubKey(regpath, RegistryKeyPermissionCheck.ReadWriteSubTree); var registData = uaes.GetValue("CurrentVersion").ToString(); return registData; }
注意,,这种方法须要添加管理员权限。。htm
解决方案二。修改弹出菜单相对于相应菜单项是左对齐仍是右对齐。(组长调出的)
public static void FixPopupBug() { var ifLeft = SystemParameters.MenuDropAlignment; if (ifLeft) { var t = typeof(SystemParameters); var field = t.GetField("_menuDropAlignment", BindingFlags.NonPublic | BindingFlags.Static); field.SetValue(null, false); } }
将win8.0下弹出菜单默认弹出到左边改成右边。 在App.xaml.cs的构造函数里调用一下。