WPF中的可拖动控件? [英] Dragable control in WPF?

查看:338
本文介绍了WPF中的可拖动控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对WPF有一些新的感觉,尽管我在Form中有一些经验,但我决定终于设法弄清楚如何使用WPF。所以当我得到可拖动的控件,这是我提出的代码(我试图改变它使用WPF,但控制只是抽搐无处不在):

  private void rectangle1_MouseMove(object sender,MouseEventArgs e)
{
if(e.LeftButton == MouseButtonState.Pressed){
double x = this.Left + (双)e.GetPosition(this).X - (double)rectangle1.Margin.Left;
double y = this.Top +(double)e.GetPosition(this).Y - (double)rectangle1.Margin.Top;
rectangle1.Margin = new Thickness(x,y,rectangle1.Margin.Right,rectangle1.Margin.Bottom);
}
}


解决方案

你想要使用装饰实现拖动,调整大小,旋转等。


Im kind of new to WPF although I have some experience in Forms, and I decided to finally try to figure out how to use WPF. So When I got to dragable controls, this is the code I came up with (I attempted to change it to work with WPF but the control just twitches everywhere):

private void rectangle1_MouseMove(object sender, MouseEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Pressed) {
        double x = this.Left + (double)e.GetPosition(this).X - (double)rectangle1.Margin.Left;
        double y = this.Top + (double)e.GetPosition(this).Y - (double)rectangle1.Margin.Top;
        rectangle1.Margin = new Thickness(x, y, rectangle1.Margin.Right, rectangle1.Margin.Bottom);
    }
}

解决方案

You want to use adorners to achieve dragging, resizing, rotating, etc.

这篇关于WPF中的可拖动控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆