我使用this文章创建了一些runtime
moveble control
在WPF
项目中,一切正常,但是当我托管{时,它一直不想工作{1}}进入WPF control
。有人知道哪里有问题?
WinForm
部分可移动C#
control
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace EvTest.Resource
{
public class MoveThumb : Thumb
{
public MoveThumb()
{
DragDelta += new DragDeltaEventHandler(this.MoveThumb_DragDelta);
}
private void MoveThumb_DragDelta(object sender, DragDeltaEventArgs e)
{
Control designerItem = this.DataContext as Control;
double left = Canvas.GetLeft(designerItem);
double top = Canvas.GetTop(designerItem);
Canvas.SetLeft(designerItem, left + e.HorizontalChange);
Canvas.SetTop(designerItem, top + e.VerticalChange);
}
}
}
控制部分:
Xaml
答案 0 :(得分:0)
我发现问题。必须是这样的:
private void MoveThumb_DragDelta(object sender, DragDeltaEventArgs e)
{
ContentControl designerItem = this.DataContext as ContentControl;
double left = Canvas.GetLeft(designerItem);
double top = Canvas.GetTop(designerItem);
Canvas.SetLeft(designerItem, left + e.HorizontalChange);
Canvas.SetTop(designerItem, top + e.VerticalChange);
}