问题
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