question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No Handler is called if ListView is inside Expander in DataTemplate

See original GitHub issue

Hey 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:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pwoestmanncommented, Sep 27, 2016

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.

0reactions
punker76commented, Sep 27, 2016

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expander inside ListBox not showing content when ...
Sounds like the content of the expander is not measured again after it is loaded, if the IsExpanded property is already set to...
Read more >
ListView - .NET MAUI
The .NET MAUI ListView displays a scrollable vertical list of selectable data items. ListView supports displaying headers and footers, ...
Read more >
Element: <oj-list-view>
Specify on any element inside an item where you want to control whether ListView should perform actions triggered by a click event originating...
Read more >
Data template selection - Windows apps
Use data template selectors to customize the styles of your items based on the item properties.
Read more >
Listview scrollbar wpf. But: When I scroll down or up so that ...
I've placed the ListView inside a ScrollViewer then taken it out again and ... I could add a margin but I do not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found