WPF C#可拖动拇指 [英] WPF C# Dragable Thumb

查看:78
本文介绍了WPF C#可拖动拇指的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





感谢您查看我的问题。



我正在尝试做一个可拖动的拇指。



通常我会这样做:



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

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





这有效,但我想知道是否有更好的方法(表现明智),也许利用Binding?



谢谢

Medz

解决方案

It不清楚你在哪里有性能损失,但不是在这个代码片段。你几乎无法提高它的表现。性能问题到底是什么?无论如何,数据绑定无法提高性能;你正在进行更基本的操作 - 为你的可拖动依赖项opject修改附加属性的值。



-SA


性能问题只是在画布上拖动拇指时显得很慢。



拇指被用作使用dragdelta的方法计算自定义对象的位置。

每个画布大约有200个自定义对象,所以我真的只是想要提高性能。



到目前为止,唯一的改进是创建私有双变量来存储最后已知的X和Y位置,这样就不必每次都查询Canvas。



如果这是最优化的,那就不要担心了。

无论如何。感谢您查看我的查询!



亲切的问候

Medz


以下解决方案可能有所帮助



WPF图设计师:第1部分 [ ^ ]

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

解决方案

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


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


the following solution may help

WPF Diagram Designer: Part 1[^]


这篇关于WPF C#可拖动拇指的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆