Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6877551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:36:49+00:00 2026-05-27T04:36:49+00:00

My Silverlight 4 app allows dragging from a ListBoxDragDropTarget to a PanelDragDropTarget. The application

  • 0

My Silverlight 4 app allows dragging from a ListBoxDragDropTarget to a PanelDragDropTarget.

The application has Person objects that are models representing people, and PersonControl user controls that have a Person as their DataContext.

For reference the relevant code is:

<toolkit:ListBoxDragDropTarget x:Name="dtListBox" Grid.Row="2" AllowedSourceEffects="Copy" AllowDrop="True" 
                               HorizontalContentAlignment="Stretch" 
                               VerticalAlignment="Top" VerticalContentAlignment="Stretch">
         <!-- FilteredMembers is of type ObservableCollection<Person> -->
    <ListBox ItemsSource="{Binding FilteredMembers}" 
                               MinWidth="42"
                               MinHeight="42">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <my:PersonControl />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
</toolkit:ListBoxDragDropTarget>

and

<toolkit:PanelDragDropTarget AllowDrop="True" AllowedSourceEffects="Copy,Move" 
              Drop="PanelDragDropTarget_Current_Drop">
    <StackPanel>
        <ctl:PersonControl Margin="3,3,3,3" x:Name="pcCurrent"></ctl:PersonControl>
    </StackPanel>
</toolkit:PanelDragDropTarget>

So far, so good. When I drag to the PanelDragDropTarget, I get a Person.

However, I also allow dragging from the PanelDragDropTarget to another PanelDragDropTarget. In that case, rather than a Person, the dropped object is a PersonControl.

So, the dropped object can be either a Person or a PersonControl depending on where it comes from.

I really want to drag and drop Person objects in all cases, rather than moving around PersonControl. How can I modify my PanelDragDropTarget so that dragging pulls the Person rather than the PersonControl?

I have reviewed this very similar question:

Drag/drop from ListBoxDragDropTarget to PanelDragDropTarget

but do not understand how that solves the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:36:50+00:00Added an answer on May 27, 2026 at 4:36 am

    You are exactly right about the difference between the way PanelDragDropTargets and ListBoxDragDropTargets transfer dropped objects. When dragging between 2 ListBoxDragDropTargets you are transferring the piece of data that is bound to the control, whereas dragging between 2 PanelDragDropTargets transfers the UIElement that is “picked up.”

    The best way I have found to get around this is to derive a new class from PanelDragDropTarget that expects a piece of data to be dropped on it instead of a UIElement. The new class stores the data object in the class’/control’s DataContext. This allows code that is similar to yours to work.

    The class:

    public class ElementDragDropTarget : PanelDragDropTarget
    {
        protected override bool CanAddItem(Panel itemsControl, object data)
        {
            return true;
        }
    
        protected override void InsertItem(Panel itemsControl, int index, object data)
        {
            itemsControl.DataContext = data;
        }
    
        protected override bool CanRemove(Panel itemsControl)
        {
            return true;
        }
    
        protected override void RemoveItem(Panel itemsControl, object data)
        {
            itemsControl.DataContext = null;
        }
    
        protected override void RemoveItemAtIndex(Panel itemsControl, int index)
        {
            itemsControl.DataContext = null;
        }
    
        protected override object ItemFromContainer(Panel itemsControl, UIElement itemContainer)
        {
            return itemsControl.DataContext;
        }
    }
    

    Edits to your code:

    <local:ElementDragDropTarget AllowDrop="True" AllowedSourceEffects="Copy,Move" Drop="PanelDragDropTarget_Current_Drop">
        <Grid>
            <ctl:PersonControl Margin="3,3,3,3" x:Name="pcCurrent"></ctl:PersonControl>
        </Grid>
    </local:ElementDragDropTarget >
    

    I realize this solution only allows one item to be dragged into the ElementDragDropTarget. I assume that is what you want to do because if you wanted to drop multiple data objects into it you should probably just use another ListBoxDragDropTarget (especially since you’re just using a StackPanel).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a simple Silverlight app that will allow people to
I have a silverlight app that allows the user to draw on it and
I have a Silverlight 5 app that gets some data from a couple Sharepoint
I'm working on a Silverlight app that would allow a user to upload a
I have a Silveright app that allows users to specify filters on a few
I am building a web app in Silverlight which allows users to view and
I have a Silverlight 4 app which pulls entities down from a database using
I'm reading everywhere the running a Silverlight app as out-of-browser allows you to use
I have a Silverlight app that is using the MVVM pattern. I have a
Here is my situation, I have an ESRI Map Silverlight application that needs to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.