网格与画布

Grid vs. Canvas(网格与画布)

本文介绍了网格与画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关在 WPF 中使用 Canvas 与 Grid 面板的意见.我需要制作具有基本网格布局的经典输入表单,有些可能内部有小数据网格、组框,但都在网格布局中对齐.我正在为我的所有表单使用网格还是画布面板而苦苦挣扎.网格给了我良好的结构;我可以更轻松地保持控件的对齐方式.我将为所有窗口提供基类(继承 Window 类),因此 Visual Studio 中的设计器将毫无用处,因为它存在这种继承的问题,并且使用 Grid 面板我什至不需要设计器,我可以设置窗口 SizeToContent 以便一切正常.但是再次使用 Canvas,我能够以任何我喜欢的方式定位控件,这是我在使用 Canvas 时看到的唯一好处.

I'm looking for opinion on using Canvas vs. Grid panels in WPF. I need to make classic input forms that have basically grid layouts, some may have small datagrids inside, groupboxes, but all aligned in grid layout. I’m struggling whether to use Grid or Canvas panel for all my forms. Grid is giving me good structure; I can maintain alignment of controls more easily¬. I will have base class (that inherits Window class) for all windows, so designer in Visual Studio will be useless, since it has issues for this sort of inheriting, and with Grid panel I don’t really even need designer, and I can set window SizeToContent so everything will fit just fine. But again with Canvas, I have ability to position controls any way I like, and this is only benefit I see when using Canvas.

我在 WPF 方面没有太多经验来预测我会从客户对布局的请求中遇到哪些问题.在网络表单上,我有时会为表单使用绝对定位,以防客户有一些特殊"要求,是否将控制像素设置在更高或更高等位置.与要求苛刻的客户一起工作的每个人都知道我的意思.

I didn’t have that much of experience in WPF to predict on what sorts of problems could I get from customer requests on layout. On web forms I sometimes use absolute positioning for forms just in case customer has some "special" request whether to have control pixel right or left on higher etc. everyone worked with demanding customers know what I mean.

我想看看您的想法,在业务应用程序表单布局构建中两者的优缺点是什么?为什么一个比另一个好?在任何情况下,一个面板会不好使用,而另一个则不会?一个面板对另一个面板有什么缺点?你会用什么面板?

I’d like to see what you think, what are pros and cons for both in business application form layout building? Why is one better than the other? Any cases where one panel would be bad to use, and other not? What are disadvantages of one panel to another? What panel would you use ?

谢谢

推荐答案

Canvas 主要用于自定义绘图功能.网格绝对是自定义布局的最佳选择.

Canvas is mostly intended for custom drawing functionality more than anything else. The grid is definitely the best choice available for customizing your layout.

这篇关于网格与画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:网格与画布

基础教程推荐