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

dachuyin dachuyin 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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外面,上面的代码能让它在整个画面随意移动,有没有大神有没有比较好的思路,谢谢
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
dachuyin
WPF/Silverlight 8,757 成员 12,031 内容