码迷,mamicode.com
首页 > 移动开发 > 详细

Popup位置随窗口移动更新

时间:2017-11-15 00:29:29      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:tar   set   property   private   dep   return   end   readonly   setvalue   

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

标签:tar   set   property   private   dep   return   end   readonly   setvalue   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!