Drop target ghost must be a UserControl

Aug 20, 2009 at 11:01 AM

Hi Kevin,

I'd like to setup the drop target ghost using some standard Silverlight controls, but I cannot because its type is a UserControl, which means I must define a custom control to use as the ghost.

To see if it didn't need to be a UserControl I changed it to be a UIElement, and everything worked fine. Is there a reason why it's currently defined as a UserControl?

If you agree that it can be UIElement, I can supply you with my changes, though as it's just a search and replace on UserControl for UIElement in DropTarget.cs (3 occurrences), it's a very simple change.

This allows me to define the drop target in XAML like this:

<UserControl x:Class="Portrait.Mas.Umd.Modules.Tagging.Controls.AssignedTags"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Toolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
             xmlns:DragDrop="clr-namespace:SL_Drag_Drop_BaseClasses;assembly=SL_Drag_Drop_BaseClasses">
    <DragDrop:DropTarget x:Name="LayoutRoot"
                         DragSourceDropped="Tag_Dropped"
                         VerticalContentAlignment="Stretch"
                         HorizontalContentAlignment="Stretch">
        <DragDrop:DropTarget.Ghost>
            <ScrollViewer VerticalScrollBarVisibility="Auto">
                <ItemsControl ItemsSource="{Binding}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Toolkit:WrapPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Button/>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </DragDrop:DropTarget.Ghost>
    </DragDrop:DropTarget>
</UserControl>

Regards,

Jim.

Coordinator
Aug 24, 2009 at 4:42 PM

He there,

 

that's indeed a shortcoming of the current release.  However, in the latest version (sourcecode), I changed this to be a FrameworkElement - so in the next release, the behaviour you're looking for will be built in! :-)

 

Kind regards,
Kevin.