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

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

问题描述

我试图弄清楚在实际渲染弹出窗口时使用了哪个传入的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://社交.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在3条路径上切换可见性以选择要渲染的正确箭头路径.

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.

因此,考虑到我们通过CustomPopupPlacementCallback delegate提供了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

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

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