Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Thanks for having a look at my question.

I am trying to make a dragable thumb.

Normally I do this:

private void thumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            posx += e.HorizontalChange;
            posy += e.VerticalChange;
        }

        public double posx
        {
            get
            {
                return Canvas.GetLeft(thumb);
            }
            set
            {
                Canvas.SetLeft(thumb, value);
            }
        }
        public double posy
        {
            get
            {
                return Canvas.GetTop(thumb);
            }
            set
            {
                Canvas.SetTop(thumb, value);
            }
        }


This works but I was wondering if there was a better way (performance wise), maybe making use of Binding?

Thanks
Medz
Posted

It is not clear where do you have a performance hit, but not at this code fragment. You hardly can improve its performance. What is exactly the problem with performance. Data binding cannot improve performance anyway; you're doing more basic operation — modify the value of attached property for your draggable dependency opject.

—SA
 
Share this answer
 
The performance issue is simply that it seems slow when dragging the thumb on a canvas.

The thumb is being used as a means to use dragdelta to calculate the position of a custom object.
Per canvas there are roughly 200 of these custom objects so I'm really just looking for anyway to improve performance.

So far the only improvement is to create private double variables to store the last known X and Y positions so that the Canvas does not have to be queried every time.

If this is as optimized as it can be then don't worry about it.
Either way. I thank you for having a look at my query!

Kind regards
Medz
 
Share this answer
 
the following solution may help

WPF Diagram Designer: Part 1[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900