WinForms 和 XAML 不能从与 CSS 相同的逻辑中受益吗?

发布于 2024-07-25 19:10:38 字数 852 浏览 7 评论 0原文

WinForms 和 XAML 不能从与 CSS 相同的逻辑中受益吗?


今天早上,当我在 Stackoverflow 上浏览一些未解答的问题时,我想到了这一点:

如果您不使用 FlowLayoutPanelTableLayoutPanel,在 WinForm 上布局控件,您会被指责做得不正确

这与 html 世界中有关 CSS 与表格

在我看来,用表格布局的 UI 的可维护性问题已被移植到 WinForms 中。 XAML(可以被认为是 HTML 的一种形式)已经包含了基于表格的布局。 如果不使用表,您将很难在 XAML 中执行任何操作。

WinForms 和 XAML 不能从与 CSS 相同的逻辑中受益吗? 桌子的维护问题就不能解决了吗? 我意识到可访问性在使用表格布局的 WinForm 或 WPF 表单上不是问题:读者不会“看到”布局面板 - 所以这是 CSS 中的问题,而 WinForms 中不存在。

但是 WinForms/XML 不能从基于非表的布局中受益吗? 我知道我当然不想在基于表格的方法中将“确定”按钮向左移动 3 个对话框单元。

Can WinForms and XAML not benefit from the same logic as CSS?


It occurred to me this morning, as I was browsing some of my unanswered questions on Stackoverflow:

If you're not using FlowLayoutPanel or a TableLayoutPanel, to layout controls on your WinForm, you'll be accused of not doing it right.

This is in contrast with the (religious) debate in html world about CSS vs Tables.

It seems to me that the maintainability problems of a UI laid out with a table has been ported to WinForms. And with XAML, which can be thought of of a form of HTML, has embraced table based layouts. You'll have a hard time doing anything in XAML without using tables.

Can WinForms and XAML not benefit from the same logic as CSS? Can the maintenance problems of tables not be done away with? I realize accessibility isn't a problem on a WinForm or WPF form laid out using tables: the reader will not "see" the layout panel - so that's a problem in CSS that doesn't exist in WinForms.

But can't WinForms/XML benefit from non-table based layouts? I know I certainly don't want to have to move that "OK" button 3 dialog units to the left in a table-based approach.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小糖芽 2024-08-01 19:10:38

我不认为你可以比较 HTML 和 XAML。 XAML 中基于表格的布局(网格)的实现远远优于 HTML 表格。 它们更容易使用,并且不会带来与 HTML 表相同的负担(跨浏览器查询)。

另外我不同意你的评论...

你会很难做任何事
在 XAML 中不使用表。

XAML 中有如此多的布局选项,您可以在不使用网格的情况下生成整个应用程序。 尽管使用网格可能更容易,但这并不意味着您在使用其他布局元素时会遇到困难。 事实上,我使用 Stackpanels 和 Canvas 的次数与使用网格的次数一样多。

这只是为每个场景使用正确元素的问题。 我来自 Web 应用程序,多年来一直在编写 HTML 和 CSS,我发现 XAML 是一种出色的标记,它使布局界面变得轻而易举……更不用说 XAML 附带的所有其他内容了。

那么回答你的问题... XAML 可以从 CSS 逻辑中受益吗? 是的,确实如此,MS 从 CSS 中汲取了很多伟大的东西,但也产生了卓越的标记。

I don't think you can compare HTML and XAML. The implementation of table based layout (Grids) in XAML is far superior to that of HTML tables. There are far easier to work with and don't come with the same baggage that HTML tables do (cross-browser querks).

Also I don't agree with your comment ...

You'll have a hard time doing anything
in XAML without using tables.

There are so many layout options in XAML, that you could produce an entire application without using a grid once. Though it may be easier to use Grids, it doesn't mean that you'd have a hard time using other layout elements. In fact, I use Stackpanels and Canvases as much as I do grids.

It just becomes a question of using the correct element for each scenario. Having come from web applications and been writing HTML and CSS for years, I find that XAML is a wonderful markup, that makes laying out your interface a breeze ... not to mention everything else that comes with XAML.

So to answer your question ... can XAML benefit from CSS logic? Yes and it does, MS has taken great things from CSS, but has also produced a superior markup.

幽梦紫曦~ 2024-08-01 19:10:38

你说:

在我看来
UI布局的可维护性问题
带有表的表已被移植到
WinForms。 通过 XAML,可以
想到一种 HTML 形式

,但您忽略了 CSS 的要点。 CSS 并不是为了避免使用表格布局,而是为了将内容与布局分离。

在 HTML 中,HTML 提供“内容”(实际文本,其结构为逻辑段落),CSS 提供有关如何布局该内容的信息(理想情况下,您可以切换 CSS 文件以适应不同的显示)方法并且相同的内容将适当地显示)

XAML/WPF 提供相同的功能(并且在较小程度上 WinForms 也提供)。 XAML(或 WinForms GUI 代码)提供布局和视觉内容。 背后的代码(最好遵循一些很好的分离模式,例如用于 WPF 或 MVC 的 MVVM WinForms)提供内容。 如果编写正确,您应该能够替换 XAML(或 WinForms GUI 代码)并为不同情况提供替代布局/GUI。

基于表格的布局没有任何问题,使用纯 HTML 表格的基于表格的布局的问题在于它将内容和布局代码混合在一起。 仅当您提供的内容本质上是表格时才应使用 HTML 表格,并且仍应使用 CSS 规则对它们进行布局和格式化。 HTML 表格不应用于布局和格式化非表格内容。

所以WPF/XAML已经像HTML+CSS一样构造,只是你比较了错误的部分。 XAML 提供布局,相当于 CSS,而背后的代码(或 mvvm 中的视图模型/模型)相当于 HTML,因为它提供内容。

You say:

It seems to me that the
maintainability problems of a UI laid
out with a table has been ported to
WinForms. And with XAML, which can be
thought of of a form of HTML

but you've missed the point of CSS. CSS isn't about avoiding use of table layouts, it's about separation of content from layout.

In HTML, the HTML provides the 'content' (the actual text, and it's structure into logical paragraphs) and the CSS provides the information about how this content should be laid out, (ideally so that you can just switch CSS files for different display methods and the same content will be displayed appropriately)

XAML/WPF provides the same ability (and to a lesser extent so does WinForms). The XAML (or WinForms GUI code) provides the layout and the visual stuff. The code behind (preferably following some nice separation pattern like MVVM for WPF or MVC in WinForms) provides the content. Written properly you should be able to swap out the XAML (or WinForms GUI code) and provide an alternative layout/GUI for different circumstances.

There is nothing wrong with table based layouts, the problem with table based layouts using plain HTML tables is that it mixes content and layout code all in one big jumble. HTML tables should only be used when the content you are providing is tabular in nature, and then they should still be laid out and formatted with CSS rules. HTML tables should not be used for laying out and formatting non tabular content.

So WPF/XAML is already structured like HTML+CSS, it's just you have compared the wrong parts. The XAML provides the layout and is the equivalent of the CSS, and the code behind (or view model / model in mvvm) is the equivalent of the HTML as it provides the content.

自此以后,行同陌路 2024-08-01 19:10:38

反对在 HTML 中使用表格进行布局的关键论据之一是语义和可访问性。 <表> 标签旨在包含表格信息,对于具有屏幕阅读器和类似功能的用户来说,使用它们进行布局可能会引起真正的头痛。 不过,XAML 中的布局容器旨在包含控件并将它们放置在用户屏幕上,将它们与相邻控件分开并对它们进行适当分组。

另一个问题是生成干净的代码。 正确标记后的 HTML 文档应该只包含文档内容,样式保留在单独的 CSS 文件中。 XAML 文件更相当于 CSS,它描述 UI 的布局,并将其与实际程序隔离,实际程序由您使用的任何语言的源文件描述。

只是因为 XAML & HTML 是 XML 风格并不意味着它们封装了相同类型的数据。 如果 CSS 是一种 XML 格式,您会将 XAML 与 HTML 或这个 (X)CSS 进行比较吗?

One of the key arguments against the use of tables for layout purposes in HTML is that of semantics and accessibility. A <table> tag is intended to contain tabular information, and for users with screen-readers and similar using them for layout purposes can cause real headaches. The layout containers in XAML, though, are meant to contain controls and position them on the user's screen, seperating them from neighbouring controls and grouping them appropriately.

Another issue is that of producing clean code. An HTML document, when marked up correctly, should just contain the document contents, with the styling kept in the seperate CSS file. A XAML file is more equivalent to the CSS, describing the layout of the UI, and isolating it from the actual program which is described by the source files of whatever language you are using.

Just because XAML & HTML are XML-ish doesn't mean they encapsulate the same sort of data. If CSS were an XML format, would you compare XAML to HTML or this (X)CSS?

沧笙踏歌 2024-08-01 19:10:38

HTML/CSS 方案的问题在于它被设计为文档 语言,而不是用户界面 语言。 演示与内容的完全分离实际上只会对文档有利。 必须用 HTML 开发用户界面简直是疯狂,因为 HTML 没有网格布局。 哦,好吧,它让我们有工作。

HTML 5 的发展方向看起来有望减少痛苦。 不过,目前我会坚持使用 Flex 和 Silverlight 等 RIA。

The problem with the HTML/CSS scheme is that it was designed as a document language, not a user interface language. The whole separation of presentation from content really only benefits documents. It is madness having to develop user interfaces in HTML, which doesn't have grid layouts. Oh well, it keeps us employed.

The direction that HTML 5 is taking looks promising for reducing the pain. For now, though, I'll stick with RIAs like Flex and Silverlight.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文