Popup位置随窗口移动更新
Posted 唐宋元明清的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Popup位置随窗口移动更新相关的知识,希望对你有一定的参考价值。
public static DependencyObject GetPopupPlacementTarget(DependencyObject obj)
{
return (DependencyObject)obj.GetValue(PopupPlacementTargetProperty);
}
public static void SetPopupPlacementTarget(DependencyObject obj, DependencyObject value)
{
obj.SetValue(PopupPlacementTargetProperty, value);
}
/// <summary>
/// Popup位置更新
/// </summary>
public static readonly DependencyProperty PopupPlacementTargetProperty =
DependencyProperty.RegisterAttached("PopupPlacementTarget", typeof(DependencyObject), typeof(PopupHelper), new PropertyMetadata(null, OnPopupPlacementTargetChanged));
private static void OnPopupPlacementTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != null)
{
DependencyObject popupPopupPlacementTarget = e.NewValue as DependencyObject;
Popup pop = d as Popup;
if (popupPopupPlacementTarget != null)
{
Window w = Window.GetWindow(popupPopupPlacementTarget);
if (null != w)
{
w.LocationChanged += delegate
{
var offset = pop.HorizontalOffset;
pop.HorizontalOffset = offset + 1;
pop.HorizontalOffset = offset;
};
}
}
}
}
以上是关于Popup位置随窗口移动更新的主要内容,如果未能解决你的问题,请参考以下文章