WPF用手习惯与弹出窗口用手、弹出窗口、习惯、WPF

由网友(梦不叹风尘)分享简介:我只是提出我的电脑的Windows 8从Windows 7,并在运行我们的WPF应用程序,我注意到我们的WPF弹出式广告和/或工具提示现在在左下默认情况下,而不是正常的右下角。有没有人注意到这一点?我知道你可以在XAML每个提示指定的位置,但我们有很多工具提示和弹出窗口。我想知道是否有一种方法可以在一个WPF应用程序在...

我只是提出我的电脑的Windows 8从Windows 7,并在运行我们的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)

同code!标准工具提示XAML属性。

Same code! Standard "tooltip" xaml attribute.

任何想法?

解决,我张贴的评论

好吧,我已经找到了问题。它必须与平板电脑/触摸屏。 (左手..右撇子preference)这等环节提供了一个理由。我工作的一个解决方案,现在解决这个问题。生病后起来的细节很快!

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

推荐答案

好了,对于那些不希望这种情况发生在所有在他们的应用程序(这是我们的愿望),我们已经创建了一个可爱的小黑客为WPF。这非常适用于我们。

Ok, for those that do not want this to occur at all in their app (which was our desire), We have created a nice little hack for WPF. This works well for us.

第一:

这code会是怎样运行它解决了问题:

This code will be what runs which fixes the issue:

public static void SetAlignment()
{
    var ifLeft = SystemParameters.MenuDropAlignment;

    if (ifLeft)
    {
        // change to false
        var t = typeof(SystemParameters);
        var field = t.GetField("_menuDropAlignment", BindingFlags.NonPublic | BindingFlags.Static);
        field.SetValue(null, false);

        ifLeft = SystemParameters.MenuDropAlignment;
    }
}

然而,环境可以去验证微软的这些值的内部缓存,所以我们必须挂钩到WinProc得到这个。我不会发布WinProc code,只是需要的信息:

However, the environment can de-validate microsofts internal cache of these values, so we have to hook into WinProc to get this. I wont post the WinProc code, just the messages that are needed:

这些是在Win32消息,这将去验证内部缓存:

These are the Win32 messages that will de-validate the internal cache:

private const int WM_WININICHANGE = 0x001A;
private const int WM_DEVICECHANGE = 0x219;
private const int WM_DISPLAYCHANGE = 0x7E;
private const int WM_THEMECHANGED = 0x031A;
private const int WM_SYSCOLORCHANGE = 0x15;

和快速的这段,将设置你的preference回来。因为我们是挂钩到WinProc,你会想后WinProc完成与其他处理的消息来改变这个值。我们有一个延迟重新设置preference值回我们想要的。

And the quick snippit that will set your preference back. Because we are hooked into WinProc, you will want to change this value after WinProc is finished with the message on other handlers. We have a delay to re-set the preference value back to what we want.

if (msg == WM_WININICHANGE || msg == WM_DEVICECHANGE || msg == WM_DISPLAYCHANGE || msg == WM_THEMECHANGED || msg == WM_SYSCOLORCHANGE)
{
    Timer timer = null;
    timer = new Timer((x) =>
        {
            WpfHelperHacks.SetAlignment();
            timer.Dispose();
        },null, TimeSpan.FromMilliseconds(2), TimeSpan.FromMilliseconds(-1));
}

就这样,它的完成。我希望这可以帮助别人!

And just like that its complete. I hope this helps someone else!

阅读全文

相关推荐

最新文章