【发布时间】:2012-03-08 22:36:36
【问题描述】:
我需要在几个 itemcontrols 之间拖动项目,每个项目都绑定到它自己的集合 当我拖动一个项目时,我需要知道它最初是从哪个项目控件中拖动的。
可拖动项目模板:
<DataTemplate>
<Ellipse MouseDown="Ellipse_MouseDown" ></Ellipse>
</DataTemplate>
项目控件:
<ItemsControl Name="Pipe23" ItemsSource="{Binding Path=Pipes[23].Checkers}" ItemTemplate="{StaticResource PipeDataItem}"/>
<ItemsControl Name="Pipe22" ItemsSource="{Binding Path=Pipes[22].Checkers}" ItemTemplate="{StaticResource PipeDataItem}"/>
<ItemsControl Name="Pipe21" ItemsSource="{Binding Path=Pipes[21].Checkers}" ItemTemplate="{StaticResource PipeDataItem}"/>
<ItemsControl Name="Pipe20" ItemsSource="{Binding Path=Pipes[20].Checkers}" ItemTemplate="{StaticResource PipeDataItem}"/>
在 MouseDown 事件上拖动项目时,我可以引用被拖动的项目,但我也需要 引用从中拖出的 itemscontrol:如何做到这一点?
private void Ellipse_MouseDown(object sender, MouseButtonEventArgs e)
{
Ellipse ellipse = (Ellipse)sender;
Checker checker = (Checker)ellipse.DataContext;
// how do i reference the itemsconrtol containing the current ellipse (item)
}
【问题讨论】:
-
Rachel 的博客有一个很好的解决方案,VisualTree helpers rachel53461.wordpress.com
标签: wpf drag-and-drop