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

  • SEARCH
  • Home
  • 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 559555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:15:00+00:00 2026-05-13T12:15:00+00:00

How do I get ListBox, Canvas and Thumb to work together? I am attempting

  • 0

How do I get ListBox, Canvas and Thumb to work together?

I am attempting to reuse the selection logic of ListBox together with a Canvas that contains draggable Thumbs.

Unfortunately the Thumb appears to handle the mouse events so that clicking on the Thumb doesn’t make the item selected.

I was hoping these elements could be made to work together without resorting to workarounds in procedural code. If anyone knows if this is possible or how to do it please advise me.

Code examples follow.

In the XAML I define the ListBox and specify a Canvas as the ItemsPanel:

<Window x:Class="ListBoxCanvasThumb.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300"
    Loaded="Window_Loaded"
    >
    <Grid>
        <ListBox
            x:Name="listBox"
            >
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>                
                    <Canvas />
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </Grid>
</Window>

In the Loaded event handler I create a draggable Thumb, wrap it in a ListBoxItem, set the positon in the Canvas and then add it to the ListBox:

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    Thumb t = new Thumb();
    t.Width = 10;
    t.Height = 10;
    t.DragDelta += new DragDeltaEventHandler(thumb_DragDelta);

    ListBoxItem i = new ListBoxItem();
    Canvas.SetLeft(i, 10);
    Canvas.SetTop(i, 10);
    i.Content = t;

    listBox.Items.Add(i);
}

In the DragDelta event handler I update the position of the item in the Canvas:

void thumb_DragDelta(object sender, DragDeltaEventArgs e)
{
    ListBoxItem i = (ListBoxItem)((Thumb)sender).Parent;
    Canvas.SetLeft(i, Canvas.GetLeft(i) + e.HorizontalChange);
    Canvas.SetTop(i, Canvas.GetTop(i) + e.VerticalChange);
}
  • 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-13T12:15:01+00:00Added an answer on May 13, 2026 at 12:15 pm

    For this purpose, your use of the Thumb control isn’t really buying you all that much, and it conflicts in several ways with what you are trying to do. I would get rid of it.

    It is very simple to make your items draggable without a Thumb by just intercepting mouse down, mouse move, and mouse up events:

    • In mouse down, set a “dragging” flag, note the current position, and capture the mouse
    • In mouse move, if “dragging” is true update Canvas.Left and Canvas.Top by the difference between the mouse position on the control and the original position
    • In mouse up, clear the “dragging” flag and clear the mouse capture

    By doing this Thumb won’t be intercepting keyboard and mouse clicks and messing with your ListBox.

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

Sidebar

Ask A Question

Stats

  • Questions 272k
  • Answers 272k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer OK, you want a nonrecursive solution which is parameterized in… May 13, 2026 at 1:59 pm
  • Editorial Team
    Editorial Team added an answer You need to define an order to the results to… May 13, 2026 at 1:59 pm
  • Editorial Team
    Editorial Team added an answer Template tags are just Python functions; you can import their… May 13, 2026 at 1:59 pm

Related Questions

How do I get this listbox to be maxiumum size, i.e. fill the group
I have a listbox (detailed view). How do I get the index of the
If I have a MultiPresenter and I am using a ListBox to display the
I have a ListBox that each of its items has a button, I set
I have a listbox with a datatemplate that holds a number of controls bound

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.