我當前在使用ItemsControl和自定義畫布時從Blend SDK使用MouseDragElementsBehavior時出現問題。我的自定義畫布根據DependencyProperty簡單地向它的子項添加或刪除MouseDragElement。當我手動將Items添加到畫布的子項時,這很好,但在移動到ItemsControl時似乎已經損壞。將MouseDragElementBehavior與ItemsControl和Canvas結合使用
我目前使用下面的ItemsControl代碼:
<ItemsControl ItemsSource="{Binding Path=CanvasItems}">
<ItemsControl.DataContext>
<ViewModels:ViewModel/>
</ItemsControl.DataContext>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<my:CustomCanvas Background="Black" IsEditable="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.CanEdit}" AllowDrop="{Binding RelativeSource={RelativeSource Self}, Path=IsEditable}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
添加在Canvas.VisualChildrenChanged方法拖動行爲不允許新創建的對象被移動像以前一樣。
是否需要將拖動行爲添加到傳遞給VisualChildrenChanged的ContentPresenter或提供特殊樣式的內容之外?
這會,如果我在做一個拖/放(已implmented)工作... DragMouseElement用於在其容器中移動的對象。 – JMcCarty 2011-06-15 15:25:46
不幸的是,我沒有Blend,所以我無法測試代碼。但我仍然會假設,MouseDragElementBehaviour會修改它附加的控件的Canvas.X附加屬性,所以它仍然應該工作。項目容器樣式應用於由ItemsControl生成的所有容器。我編輯了代碼以反映我見過的混合行爲的樣本。 – 2011-06-15 16:36:28
您提供的樣式導致參數計數不匹配錯誤。你碰巧記得你在哪裏看到這些樣品,以便我可以看看? – JMcCarty 2011-06-15 17:43:30