WPF canvas内部拖动控件的时候关于不能拖到边界外面的问题,该控件还用装饰器

dachuyin 2017-09-29 11:42:46
private void LeftMouseButtonDowm_Body(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount > 1 && _adornedElement is TreeView)
{
TreeView ctrl = _adornedElement as TreeView;
_body.IsHitTestVisible = false;
ctrl.IsHitTestVisible = true;
Keyboard.Focus(ctrl);
return;
}
_startLocation = new Point((double)_adornedElement.GetValue(Canvas.LeftProperty), (double)_adornedElement.GetValue(Canvas.TopProperty));
_startHeight = (double)AdornedElement.GetValue(FrameworkElement.HeightProperty);
_startWidth = (double)AdornedElement.GetValue(FrameworkElement.WidthProperty);
_dragLocation = Mouse.GetPosition(_canvas);
_isDraging = true;
(sender as Rectangle).CaptureMouse();
}
private void MouseMove_Body(object sender, MouseEventArgs e)
{
if (_isDraging)
{
Point parentCanvas = Mouse.GetPosition(_canvas);
if (parentCanvas.X >= 15)
{
_adornedElement.SetValue(Canvas.LeftProperty, _startLocation.X + (parentCanvas.X - _dragLocation.X));
_adornedElement.SetValue(Canvas.TopProperty, _startLocation.Y + (parentCanvas.Y - _dragLocation.Y));
}
}
}


textbox套了装饰器,就是body,现在在canvas里面拖动这个body,但是body不能移到canvas外面,上面的代码能让它在整个画面随意移动,有没有大神有没有比较好的思路,谢谢
...全文
718 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
exception92 2017-10-11
  • 打赏
  • 举报
回复
不能拖到边界外面的问题,该控件还用装饰器 -》这跟用什么没关系吧,跟你的拖动的时候 判断top/left 逻辑 有关系。

8,735

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧