【发布时间】:2014-07-17 15:32:24
【问题描述】:
我有课
public class DrawingCanvas : FrameworkElement
它使用 MouseDragElementBehavior 来实现拖动。
我想将 DrawingCanva 像 Photoshop 中的一个图层一样相对于另一个图层拖动
单独使用(图片 #1 上的 XAML)
<Grid x:Name="_layoutRootControl">
<Canvas
Grid.Column="0">
<canvas:DrawingCanvas />
<canvas:DrawingCanvas />
</Canvas>
</Grid>
do 允许拖动,但是当我将 DrawingCanvas 放在 ItemsControl 内时 并将 ItemsSource 绑定到项目集合,拖动不起作用。 (图片 #2 上的 XAML)
<ItemsControl ItemsSource="{Binding Source={StaticResource Locator}, Path=LayersViewModel.Layers}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="0" />
<Setter Property="Canvas.Top" Value="0" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<canvas:DrawingCanvas />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我不明白为什么。
第一种情况是以下 XAML 结构:
第二种情况是下面的XAML结构:
更新:
我发现在 ItemsControl 的第二种情况下,DrawingCanvas.Parent = null
【问题讨论】:
-
你能提供更多细节吗?你想拖动什么,
DrawingCanvas中的项目,还是DrawingCanvas本身?您能否也提供您的ItemsControl的 XAML? -
是的,我会更新主题并提供更多细节
-
我发现在第二种情况下 ItemsControl DrawingCanvas.Parent = null
标签: wpf drag itemscontrol