首页 > 移动平台 > 详细

Popup位置随窗口移动更新

时间:2017-11-14 23:53:00      阅读:437      评论:0      收藏:0      [点我收藏+]

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位置随窗口移动更新

原文:http://www.cnblogs.com/kybs0/p/7835353.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!