Canvas和电网之间的区别,以移动,缩放,旋转UI元素 [英] Difference between Canvas and Grid to Move, Resize, Rotate UIElements

查看:187
本文介绍了Canvas和电网之间的区别,以移动,缩放,旋转UI元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发可动态添加控件后移动,缩放或旋转建立与此UI元素窗口的编辑器。

I want to develop a editor that can add dynamically Controls and after to move, resize or rotate to build a window with this UIElements.

我的问题是谁对一个集装箱这个UI元素的,网格或画布?

画布更好的绝对位置的工作,也许有更好的精度转化。但不太敏感,当我将在不同的屏幕分辨率显示的应用程序?我并不非常了解,从电网或帆布的优点/缺点

Canvas are working in absolute position, maybe have better precision for transforming. But is less responsive when I will display the App in different screen resolutions? I doesn't know very well about the pros/cons from Grid or Canvas.

我打了一个比方用帆布和网格来移动的UIElement使用此代码:

I made a example with a Canvas and Grid to move a UIElement with this code:

private void ui_MouseMove(object sender, MouseEventArgs e)
    {
        if (m_IsPressed)
        {
            UIElement ui = (UIElement)sender;
            TranslateTransform transform = new TranslateTransform();
            transform.X = Mouse.GetPosition(MyGridOrCanvas).X;
            transform.Y = Mouse.GetPosition(MyGridOrCanvas).Y;
            ui.RenderTransform = transform;
        }
    }



但与帆布或网格,当我点击的UIElement并没有移动,的UIElement总是从我的光标移到X,Y。也许是没有做到这一点的最好办法。 如果您还教程如何建立这一功能将帮助我。我是新这个东西。

非常感谢你!和问候

推荐答案

我就为这个问题进行的这很可能是由社区这里太主观关闭。我可以看到已经一个比较接近的投票。

I'll just provide a short answer for this question as it is likely to be closed by the community here for being too subjective. I can see one close vote already.

所以,在我看来,在画布是一个更好的控制使用用于此目的。原因之一,它不具有的的大量布局要求,所以它是更有效的。另一个主要的原因是使用 Canvas.Top Canvas.Left 属性挪动的物品是完美的.. 。其他面板 S IN移动项目,你经常凑合设置保证金属性来代替,这是很不理想。

So, in my opinion, the Canvas is a much better control to use for this purpose. For one reason, it does not have the considerable layout requirements of the Grid and so it is more efficient. The other main reason is that using the Canvas.Top and Canvas.Left properties to move the items is perfect... to move items in other Panels, you often have to make do with setting the Margin property instead, which is far from ideal.

至于你的项目被点击......这只是在你的代码做了一个错误,当移动时,它的的的正常行为 - 控制将不自行移动,除非我们告诉它

As for your items moving when being clicked on... that's just a bug in your code doing that, it's not the normal behaviour - a control won't move on its own unless we tell it to.

这篇关于Canvas和电网之间的区别,以移动,缩放,旋转UI元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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