Search code examples
.netwpfxamlwindows-8tooltip

WPF Handedness with Popups


I just moved my PC to Windows 8 from Windows 7 and while running our WPF application I noticed that our WPF popups and/or tool tips are now in the lower-left by default instead of the normal lower right. Has anyone noticed this? I know you can specify their location on each tooltip in the xaml, but we have a lot of tool tips and popups. I want to know if there is a way to specify the default location globally in a WPF app. Google hasn't yielded many results on this subject. We have a reason to keep them in the same original default position (some popups have content relative to their start up position).

Windows 8: (Lower left)

Tool Tip on Win8

Windows 7: (Lower right)

Tool Tip on Win7

Same code! Standard "tooltip" xaml attribute.

Any ideas?

RESOLVED AND I POSTED THE COMMENTS


Ok, I have found the issue. It has to do with Tablet PCs/Touchscreens. (left handed.. right handed preference) This other link provided a reason. I am working on a solution to resolve this now. Ill post up the details soon!

windows 8 popup location


Solution

  • Thanks @TravisWhidden for the solution. Just implemented an improved version of it that listens to the StaticPropertyChanged event, I'll paste it in here because it seems less of a "hack".

    private static readonly FieldInfo _menuDropAlignmentField;
    static MainWindow()
    {
        _menuDropAlignmentField = typeof(SystemParameters).GetField("_menuDropAlignment", BindingFlags.NonPublic | BindingFlags.Static);
        System.Diagnostics.Debug.Assert(_menuDropAlignmentField != null);
    
        EnsureStandardPopupAlignment();
        SystemParameters.StaticPropertyChanged += SystemParameters_StaticPropertyChanged;
    }
    
    private static void SystemParameters_StaticPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        EnsureStandardPopupAlignment();
    }
    
    private static void EnsureStandardPopupAlignment()
    {
        if (SystemParameters.MenuDropAlignment && _menuDropAlignmentField != null)
        {
            _menuDropAlignmentField.SetValue(null, false);
        }
    }