w8 default tablet settings conflicts with WPF layout

江枫思渺然 提交于 2020-01-24 08:49:32

问题


I have a WPF desktop app. I've gotten reports from W8 users that the code completion window in our app is not aligned correctly. I investigated and found out that its a setting in W8 tablet settings that conflicts with the placement of popups in wpf

Default is right handed and then the code completion popup looks like this

When changed to left handed the code completion popup renders correctly like this

Is there a way to programmaticly force the app to use left handed settings, or ignore it completely so it renders like in w7?

edit: Got an upwote so can update with solution, requires .NET 4.5

private static readonly FieldInfo MenuDropAlignmentField;

static MyWindow()
{
    MenuDropAlignmentField = typeof (SystemParameters).GetField("_menuDropAlignment",
        BindingFlags.NonPublic | BindingFlags.Static);
    System.Diagnostics.Debug.Assert(MenuDropAlignmentField != null);

    EnsureStandardPopupAlignment();
    SystemParameters.StaticPropertyChanged += (s, e) => EnsureStandardPopupAlignment();
}

private static void EnsureStandardPopupAlignment()
{
    if (SystemParameters.MenuDropAlignment && MenuDropAlignmentField != null)
    {
        MenuDropAlignmentField.SetValue(null, false);
    }
}

Full code here

https://github.com/AndersMalmgren/FreePIE/blob/master/FreePIE.GUI/Shells/MainShellView.xaml.cs

来源:https://stackoverflow.com/questions/17858055/w8-default-tablet-settings-conflicts-with-wpf-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!