Wpf控件移动在托管到WinForm时不起作用

时间:2012-09-11 16:23:26

标签: c# wpf winforms integration

我使用this文章创建了一些runtime moveble controlWPF项目中,一切正常,但是当我托管{时,它一直不想工作{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

1 个答案:

答案 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);

}