确定用于 WPF 弹出窗口的 CustomPopupPlacement [英] Determining which CustomPopupPlacement was used for WPF Popup

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

问题描述

我试图找出在实际呈现弹出窗口时使用了传入的 CustomPopupPlacement 位置数组中的哪一个.有什么事件可以检测到这一点吗?

I'm trying to figure out which of the passed in array of CustomPopupPlacement positions have been used when the popup actually renders. Is there any event to detect this?

这个 2009 年的 msdn 线程似乎正是我的问题,但似乎没有答案.

This msdn thread from 2009 seems to be exactly my issue however there does not seem to be an answer for it.

http://social.msdn.microsoft.com/Forums/da/wpf/thread/4c6d216a-0011-4202-aa7e-2fccef3cc355

标记的答案似乎无效,我的情况与线程中的 OP 完全相同.

The marked answer seems invalid and my situation is exactly as the OP in the thread.

我将弹出带有 4 条路径的弹出窗口,并使用 DP 来切换三个路径的可见性,以选择要渲染的正确箭头路径.

I'm going to have my popup with 4 paths and use a DP to toggle visibility on three paths to choose the correct arrow path being rendered.

因此,鉴于我们通过 CustomPopupPlacementCallbackdelegate 提供了 4 个放置选项,有没有办法检测系统在处理屏幕边缘情况和排序后最终选择的 4 个位置中的哪一个.

So given we provide 4 placement options via the CustomPopupPlacementCallbackdelegate, Is there a way to detect which of the 4 positions the system finally chose after dealing with screen edge cases and the sorts.

推荐答案

我有一个小技巧.将自定义点保存为派生的 TooTip 类中的字段并覆盖 OnOpened 方法.

I have a little hacky solution. Save the custom points as fields in the derived TooTip class and override the OnOpened method.

protected override void OnOpened(RoutedEventArgs e)
{
    base.OnOpened(e);
    var p = this.TranslatePoint(new Point(0, 0), this.PlacementTarget);
    var diff1 = this.first - p;
    var diff2 = this.second - p;

    if (Math.Abs(Math.Min(diff1.Length, diff2.Length) - diff1.Length) < 0.01)
    {
        // First Point
    }
    else
    {
        // Second Point
    }
}

欢迎提供更好的解决方案

Better solutions are welcome

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

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