带有弹出窗口的 WPF 惯用手 [英] WPF Handedness with Popups

查看:32
本文介绍了带有弹出窗口的 WPF 惯用手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我的 PC 从 Windows 7 移到了 Windows 8,在运行我们的 WPF 应用程序时,我注意到我们的 WPF 弹出窗口和/或工具提示现在默认位于左下角,而不是正常的右下角.有没有人注意到这一点?我知道您可以在 xaml 的每个工具提示上指定它们的位置,但是我们有很多工具提示和弹出窗口.我想知道是否有办法在 WPF 应用程序中全局指定默认位置.谷歌在这个主题上没有产生很多结果.我们有理由将它们保持在相同的原始默认位置(某些弹出窗口的内容与其启动位置相关).

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:(左下)

Windows 8: (Lower left)

Windows 7:(右下)

Windows 7: (Lower right)

相同的代码!标准的工具提示"xaml 属性.

Same code! Standard "tooltip" xaml attribute.

有什么想法吗?

已解决并发表评论

好的,我找到了问题所在.它与平板电脑/触摸屏有关.(左撇子……右撇子偏好)另一个链接提供了一个原因.我现在正在研究解决这个问题的解决方案.我会尽快发布详细信息!

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 弹出位置

推荐答案

感谢 @TravisWhidden 的解决方案.刚刚实现了它的一个改进版本,它可以监听 StaticPropertyChanged 事件,我将把它粘贴在这里,因为它看起来不像黑客".

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);
    }
}

这篇关于带有弹出窗口的 WPF 惯用手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆