ratishphilip / wpfspark

A rich UserControl library to enhance the look and feel of WPF applications.
http://www.codeproject.com/Articles/1060961/WPFSpark-v
MIT License
549 stars 84 forks source link

Fix FluidWrapPanel drag'n'drop not working when the dragged element is a descendant of the panel child item #17

Closed jgonzalez-stw closed 1 year ago

jgonzalez-stw commented 1 year ago

When using FluidWrapPanel as the items panel template of a ItemsControl (e.g., to generate child items from a binding MVVM-style), element rearrangement by drag'n'drop was not working because the elements generated from DataTemplate are children of a ContentPresenter, which is the real child panel item added to the FluidWrapPanel. Since FluidMouseDragBehavior is not attached directly to the FluidWrapPanel child but to one of its descendents, the drag begin event was being ignored.

The solution generalizes the solution for the similar problem found with ListBoxes.

Usage example that reproduces the problem:

<ItemsControl ItemsSource="{Binding MyListOfStuff}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <wpfspark:FluidWrapPanel IsComposing="True"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Grid>
                <i:Interaction.Behaviors>
                    <wpfspark:FluidMouseDragBehavior DragButton="Left"></wpfspark:FluidMouseDragBehavior>
                </i:Interaction.Behaviors>
                <TextBlock Text="{Binding Name}" Margin="30"/>
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>