No Handler is called if ListView is inside Expander in DataTemplate
See original GitHub issueHey really great work so far !
Im expecting an Issue when using multiple ListViews wrapped in an expander where Items shall be dragged between.
My Models are three Collections of Classes where the view is bound to.
class Geometry -Name Property
class Target -Name Property
class Path -Name Property -tbTargets “ICollection of Target”
My ViewModel has the Models as three Properties
ObservableCollection<Geometry> Geometries ObservableCollection<Target> Targets ObservableCollection<Path> Paths
My View is of the following structure `<UserControl.Resources>
<DataTemplate x:Key="GeometryTemplate">
<Label Content="{Binding Name}" />
</DataTemplate>
<DataTemplate x:Key="TargetTemplate">
<Label Content="{Binding Name}" />
</DataTemplate>
<DataTemplate x:Key="PathTemplate">
<Expander Header="{Binding Name}">
<ListView ItemsSource="{Binding tbTargets}" ItemTemplate="{StaticResource TargetTemplate}" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}" dd:DragDrop.DragHandler="{Binding}" />
</Expander>
</DataTemplate>
<Style TargetType="{x:Type Expander}" BasedOn="{StaticResource {x:Type Expander}}">
<Setter Property="Background" Value="{DynamicResource WhiteBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource WhiteBrush}"/>
</Style>
</UserControl.Resources>
<Grid>
<StackPanel Orientation="Vertical">
<Expander Header="Geometries">
<ListView ItemsSource="{Binding Geometries}" ItemTemplate="{StaticResource GeometryTemplate}" MaxHeight="200" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}" dd:DragDrop.DragHandler="{Binding}"/>
</Expander>
<Expander Header="Targets">
<ListView ItemsSource="{Binding Targets}" ItemTemplate="{StaticResource TargetTemplate}" MaxHeight="200" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}" dd:DragDrop.DragHandler="{Binding}"/>
</Expander>
<Expander Header="Paths">
<ListView ItemsSource="{Binding Paths}" ItemTemplate="{StaticResource PathTemplate}" MaxHeight="200" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}" dd:DragDrop.DragHandler="{Binding}"/>
</Expander>
</StackPanel>
</Grid>
</UserControl>`
If i drag between the Geometries and Targets collection the Drag Handler is called, when im dragging in the Paths child collection not. Is this an issure or am I doing something wrong?
Thank you very much in advance
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Ive managed to get it working! I forgot about the missing connection between the DataTemplate and parent element DataContext . So if i set the Handlers to:
dd:DragDrop.DropHandler="{Binding DataContext,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" dd:DragDrop.DragHandler="{Binding DataContext,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
everything works as expected and very awesome!
I would like to apologize myelf for insinuating errors in your code 😦 Maybe you add this trick to the documentation.
Thank you very much for your fast and professional help.
@pwoestmann Thx. And you don’t need to apologize yourself. I’m also not perfect 😉 I will add a note to this if someone uses only one DragHandler/DropHandler.