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 3699030
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:03:13+00:00 2026-05-19T05:03:13+00:00

I have a ListBox (with ItemTemplate defined in the XAML), and a DataGrid. I

  • 0

I have a ListBox (with ItemTemplate defined in the XAML), and a DataGrid.
I would like to perform drag and drop operations from the DataGrid to the ListBox.
My problem is I don’t understand how to know on which ListBoxItem the dragged row has been dropped.

Does anyone have an idea ?

Thanks in advance.

Edit: Here is the ListBox’s XAML:

<toolkit:DockPanel Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Width="200">
            <toolkit:ListBoxDragDropTarget Name="dropTarget1"  AllowDrop="True" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" AllowedSourceEffects="Move">
                <ListBox Name="lbClusters">

                    <!-- Override default HorizontalContentAlignment -->
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
                        </Style>
                    </ListBox.ItemContainerStyle>

                    <!-- Override default presentation panel (to be able to organize) -->
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>

                    <!--  Items presentation -->
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Border BorderBrush="Black" BorderThickness="1" Margin="5">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>

                                    <Border Background="Gray" Padding="10,5,0,5" Grid.Row="0" >
                                        <TextBlock Text="{Binding Name}" HorizontalAlignment="Stretch" />
                                    </Border>
                                    <ListBox ItemsSource="{Binding MatchingProcessors}" DisplayMemberPath="Name" Grid.Row="1" MinHeight="100" />
                                </Grid>
                            </Border>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </toolkit:ListBoxDragDropTarget>
        </toolkit:DockPanel>

And here is the DataGrid:

<toolkit:DataGridDragDropTarget VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch">

                <sdk:DataGrid Name="Grid1" SelectionChanged="Grid_SelectionChanged" AutoGenerateColumns="False">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Binding="{Binding Configuration.Nickname}" Header="NickName" />
                        <sdk:DataGridTextColumn Binding="{Binding SerialNumber}" Header="SN" />
                        <sdk:DataGridTextColumn Binding="{Binding ComputerName}" Header="IPHostname"/>
                        <sdk:DataGridTextColumn Binding="{Binding Configuration.GroupName}" Header="Group" />
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>

            </toolkit:DataGridDragDropTarget>
  • 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-19T05:03:14+00:00Added an answer on May 19, 2026 at 5:03 am

    Ok here is what I did… Maybe there is a better solution ? But this one seems to fit what I need.

    I changed my ListBox.ItemTemplate to add 2 events: MouseEnter and MouseLeave on the Grid:

    <ListBox.ItemTemplate>
    <DataTemplate>
        <Border BorderBrush="Black" BorderThickness="1" Margin="5">
            <Grid MouseEnter="Grid_MouseEnter" MouseLeave="Grid_MouseLeave">
                <Grid.RowDefinitions>                                            
                    <RowDefinition />                                            
                    <RowDefinition />
                </Grid.RowDefinitions>
    
                <Border Background="Gray" Padding="10,5,0,5" Grid.Row="0" >
                    <TextBlock Text="{Binding Name, Mode=TwoWay}" HorizontalAlignment="Stretch" />
                </Border>
                <ListBox ItemsSource="{Binding MatchingProcessors, Mode=TwoWay}" DisplayMemberPath="SerialNumber" Grid.Row="1" MinHeight="100" />
            </Grid>
        </Border>
    </DataTemplate>
    </ListBox.ItemTemplate>
    

    Then in the code I implemented thos events, and keep a reference to the hovered element in the ListBox.

        private ListBoxItem currentListBoxItem = null;
    
        private void Grid_MouseEnter(object sender, MouseEventArgs e)
        {
            List<UIElement> list = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null), LayoutRoot as UIElement) as List<UIElement>;
            var tmp = list.OfType<ListBoxItem>().Where(el => el.DataContext != null && el.DataContext is MyType).FirstOrDefault();
    
            if (tmp != null)
            {
                this.currentListBoxItem = tmp;
            }
        }
    
        private void Grid_MouseLeave(object sender, MouseEventArgs e)
        {
            this.currentListBoxItem = null;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox defined like this: <ListBox.ItemTemplate> <DataTemplate> <ItemsControl> <!-- Contents here -->
I have a ListBox with a rather simple ItemTemplate defined - containing a TextBlock
I have a listbox, which is defined like so: <ListBox ItemsSource={Binding Source={x:Static local:ResourceCollection.resourceList}} Height=143
I have a ListBox like this : <ListBox DataContext={Binding UpdateSourceTrigger=PropertyChanged} ItemsSource={Binding UpdateSourceTrigger=PropertyChanged} ListBoxItem.Selected=ListBoxItem_Selected> <ListBox.ItemTemplate>
I'm developing a Windows Phone application. I have defined a ListBox.ItemTemplate's DataTemplate as follows:
I have a listbox which has templates defined for the ItemContainer and the ItemTemplate
I have a listbox where the items contain checkboxes: <ListBox Style={StaticResource CheckBoxListStyle} Name=EditListBox> <ListBox.ItemTemplate>
I have a databound and itemtemplated ListBox: <ListBox x:Name=lbLista ScrollViewer.VerticalScrollBarVisibility=Visible> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal>
I have this: <ListBox x:Name=PART_lstAttributes Grid.Row=1 Style={StaticResource GlossyBlackListBox}> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock x:Name=txtAttributeName Text={Binding
I have a listbox, and I have the following ItemTemplate for it: <DataTemplate x:Key=ScenarioItemTemplate>

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.