Gong-wpf-dragdrop: Listbox horizontal line not showing

Created on 25 Aug 2016  ·  7Comments  ·  Source: punker76/gong-wpf-dragdrop

I can't figure it out why the gray horizontal line does not show when dragging items to ListBox. Is there some trick here?

<Window x:Class="EmptyListBoxWithDragAndDrop.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:gong="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
        Title="MainWindow" Height="600" Width="800" WindowStartupLocation="CenterScreen">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <ListBox Grid.Column="0" ItemsSource="{Binding Source}"
                 gong:DragDrop.IsDragSource="True" gong:DragDrop.UseDefaultEffectDataTemplate="True"/>

        <ListBox Grid.Column="1" ItemsSource="{Binding Target}" 
                 gong:DragDrop.IsDropTarget="True" gong:DragDrop.DropHandler="{Binding}">
            <ListBox.Style>
                <Style  TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
                    <Style.Triggers>
                        <Trigger Property="HasItems" Value="False">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate>
                                        <TextBlock Text="Drag items from left ListBox" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListBox.Style>
        </ListBox>
    </Grid>
</Window>

I even remove the trigger style, but it doesn't work, no horizontal line is shown.
This is the line I'm talking about:

untitled

Most helpful comment

Is there some trick here?

So there is a catch :D Thanks, it worked!

And you should give your custom template a background to allow target drop at the whole client size

I can't believe it! Thanks a lot, I've been banging my head over this (my stackoverflow question)

All 7 comments

@JobaDiniz If a ItemsControl is empty no DropTargetInsertionAdorner will be shown.

But it is not empty, here is the sample.

@JobaDiniz :-D I should use a default for this to avoid such issues...

public void DragOver(IDropInfo dropInfo)
{
    // you must say which adorner you want if you implement the IDropTarget interface
    dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
    // or you call the DragOver method from the default DefaultDropHandler to get the adorner
    //GongSolutions.Wpf.DragDrop.DragDrop.DefaultDropHandler.DragOver(dropInfo);

    if (dropInfo.Data is string)
        dropInfo.Effects = System.Windows.DragDropEffects.Copy;
}

2016-08-25_16h12_07

@JobaDiniz And you should give your custom template a background to allow target drop at the whole client size

<ControlTemplate>
    <Grid Background="{TemplateBinding Background}">
        <TextBlock Text="Drag items from left ListBox" VerticalAlignment="Center" HorizontalAlignment="Center"/>
    </Grid>
</ControlTemplate>

Is there some trick here?

So there is a catch :D Thanks, it worked!

And you should give your custom template a background to allow target drop at the whole client size

I can't believe it! Thanks a lot, I've been banging my head over this (my stackoverflow question)

@JobaDiniz Just answered ;-)

I will add a new attached property to allow showing the target adorner on empty ItemsControls.

ShowDropAdornerOnEmptyTarget

or is there a better name?

I will add a new attached property to allow showing the target adorner on empty ItemsControls

I don't know if this is really required. My issue was something else.

Was this page helpful?
0 / 5 - 0 ratings