在ListBoxDragDropTarget中更改DragDecorator的默认移动

时间:2013-03-13 10:01:48

标签: c# silverlight-4.0 drag-and-drop silverlight-toolkit

我正在使用Silverlight Toolkit中的ListBoxDragDropTarget,我想在拖动项目时更改项目的移动。因此,在我的ListBox面板中,它应该只能在面板内移动,并且只允许垂直移动不是水平的。

默认情况下,您可以在整个应用程序中移动ListBox中的项目,并且我不会知道它只能在ListBox中移动。

所以我尝试的是更改PopupControl和DragDecoratorControl的RenderTransform,甚至是模板内的Canvas。

public class FixedListBoxDragDropTarget : ListBoxDragDropTarget
{
    public Popup DragPopupControl { get; set; }
    public DragDecorator DragDecoratorControl { get; set; }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        DragPopupControl = GetTemplateChild(DragPopupName) as Popup;
        DragDecoratorControl = GetTemplateChild(DragDecoratorName) as DragDecorator;
    }
}

在ListBoxItems上附加了MouseMove事件

private void TopicUsedControl_MouseMove_1(object sender, System.Windows.Input.MouseEventArgs e)
{
    //Get the Control
    var dragDropPanel = UIHelper.FindChild<FixedListBoxDragDropTarget>(Application.Current.RootVisual, "DragDropControl");

    var transform = dragDropPanel.DragPopupControl.RenderTransform as CompositeTransform;
    var transformDragdecorator = dragDropPanel.DragDecoratorControl.RenderTransform as CompositeTransform;
    if (transform == null && transformDragdecorator == null)
    {
        transform = new CompositeTransform();
        transformDragdecorator = new CompositeTransform();
        dragDropPanel.DragPopupControl.RenderTransform = transform; //PopupControl of Template
        dragDropPanel.DragPopupControl.Child.RenderTransform = transform; //Canvas inside the Template
        dragDropPanel.DragDecoratorControl.RenderTransform = transformDragdecorator; // Dragdecorator of Template
    }

    transform.TranslateX = 0;
    transform.TranslateY = 10;
    transformDragdecorator.TranslateX = 0;
    transformDragdecorator.TranslateY = 10;
}

我试图将RenderTranform设置为固定值,控件不再移动以测试它。但它没有发生任何事情,我可以用鼠标移动控件,上面的代码没有任何影响。

如何更改或更改覆拖拉机的默认移动行为?

0 个答案:

没有答案