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

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

问题描述

我对WPF还是很陌生,尽管我有一些Forms的经验,所以我决定最终尝试弄清楚如何使用WPF。因此,当我要拖动控件时,这是我想到的代码(我试图将其更改为与WPF一起使用,但控件随处可见)

p> private voidrectangular1_MouseMove(对象发送方,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;
rectangular1.margin =新的厚度(x,y,rectangular1.Margin.Right,rectangular1.Margin.Bottom);
}
}


解决方案

您想要使用装饰来实现拖动,调整大小,旋转等操作。


I'm 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 draggable 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天全站免登陆