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 を Fixed 値に設定して、コントロールがもう動かないことをテストしてみました。しかし、マウスでコントロールを動かすことはできず、上記のコードは何の効果もありません。
ドラッグデコレータのデフォルトの移動動作を変更またはオーバーライドするにはどうすればよいですか?