我正在编写一个控件,允许您拖动子控件上的元素。我这样做是通过创建ItemsControl并绑定Manipulation事件来重新排序元素(就像你可以使用listview,但在视觉上非常不同)。但是,当我实际更改根面板上子项的顺序时,actionsCompleted事件将触发,并且没有进一步的manipDelta事件(即使指针或手指仍然向下并移动)。
XAML snipppet:
<ItemsControl.Template>
<ControlTemplate>
<Grid x:Name="TopGrid"
ManipulationMode="TranslateX,TranslateY"
ManipulationStarted="TopGrid_ManipulationStarted"
ManipulationDelta="TopGrid_ManipulationDelta"
ManipulationCompleted="TopGrid_ManipulationCompleted">
<ItemsPresenter />
</Grid>
</ControlTemplate>
</ItemsControl.Template>
而C#似乎导致操纵结束。这是在ManipulationDelta事件处理程序中:
List<UIElement> children = new List<UIElement>();
children.AddRange(wp.Children.Where(u => (u as ContentPresenter)?.Content != _dragObject).Take(current));
children.Add(wp.Children.First(u => (u as ContentPresenter)?.Content == _dragObject));
children.AddRange(wp.Children.Where(u => (u as ContentPresenter)?.Content != _dragObject).Skip(current));
ItemsPanelRoot.Children.Clear();
children.ForEach(u => ItemsPanelRoot.Children.Add(u));