Hello,
Welcome to Microsoft Q&A!
How to drag ListBoxItem?
To enable dragging on an element, set its CanDrag property to true. In your scenario, you need to set the CanDrag property of the root element of the Content of ListBoxItem
.
I've made a simple demo about this so you could understand it better:
Grid grid = new Grid();
grid.CanDrag = true;
TextBlock block = new TextBlock();
block.Text = "123";
grid.Children.Add(block);
ListBoxItem item = new ListBoxItem();
item.Content = grid;
MyListBox.Items.Add(item);
The Grid
is the root element of the Content of ListBoxItem
, so make it draggable by enable the CanDrag property of the Grid. Then you could drag the Item.
Please check the document Drag and drop for more information about how to handle the drag and drop event.
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.