动态生成的XAML
我正在努力生成一个小型应用程序,该应用程序从 URL 解析 XML 并根据 XML 的内容填充网格面板。目前,我有许多其他元素正常工作,但仍然缺乏隐藏或显示表中某些列以及正确调整其大小所需的知识。这是到目前为止我的 XAML 的基本结构。
目前,我觉得我的解决方案很差。我对网格中的每个列和行进行了硬编码,并将它们的可见性与转换器后面的代码联系起来。在某些条件下,此转换器将返回隐藏的可见性,但在其他条件下,它返回要在表中显示的值。这对我来说感觉非常草率,所以我认为我设计的这个系统是错误的。
我的问题更多是关于设置此类系统的正确方法。我更熟悉在某些业务逻辑中生成文档结构本身,然后用原始文档本身内部的令牌交换生成的结构。实现我所追求的目标的最佳方法是什么?
I am working towards producing a small application that parses XML from a URL and populates a Grid panel based on the contents of the XML. Currently, I have many other elements working properly, but still lack the knowledge needed to hide or show certain columns within the table and having it resize properly. Here's the basic structure of my XAML thus far.
Currently, I feel as though my solution is very poor. I have hard coded each coulmn and row within the Grid and tied their Visibility to a code behind Converter. Under certain conditions, this Converter will return a Visibility of Hidden, but under other conditions it returns the value to display within the table. This feels very sloppy to me, so I assume I've designed this system incorrectly.
My question is more about the proper way to setup this type of system. I am much more familiar with generating the document structure itself within some business logic and then token swapping that generated structure with a token inside the raw document itself. What is a best way to accomplish the goal I'm pursuing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以提供从 Web 服务检索到的
XDocument
或XElement
作为带有ItemsControl
的DataContext
>网格。然后,您将使用DataTemplate
来显示信息。XML:
代码隐藏:
XAML:
Linq to XML 资源:
You could provide the
XDocument
orXElement
retrieved from the web service as theDataContext
of anItemsControl
with aGrid
. You would then use aDataTemplate
to display the information.XML:
Code Behind:
XAML:
Linq to XML resources: