[英]How do I dynamically create ListBox items from code in C# (Winrt)
I'm hoping someone can point me in the right direction here, 我希望有人可以在这里指出正确的方向,
I am faced with the task of creating a screen that I must construct using a message sent to me from over a socket. 我面临的任务是创建一个屏幕,必须使用通过套接字发送给我的消息来构造屏幕。 The screen can consist of your standard GUI items, and this includes a list/table. 该屏幕可以包含您的标准GUI项,其中包括一个列表/表。 I can see plenty of code and tips on how to create a table using a DataTemplate in XAML, however I have 2 (related) things which I am struggling with. 我可以看到很多代码和有关如何在XAML中使用DataTemplate创建表的提示,但是我有2件(相关的)问题在困扰着我。
What is the best way to create a list from code (WinRT/c#), that may contain a complicated component heirachy (buttons/images inside a panel laid out by me). 从代码(WinRT / c#)创建列表的最佳方法是什么,该列表可能包含一个复杂的组件(由我布置的面板内的按钮/图像)。 I see that the ItemContainerGenerator is a sealed class so I can't roll my own... Do I create my own DataTemplate via code some how? 我看到ItemContainerGenerator是一个密封的类,所以我不能自己滚动……我是否通过代码创建自己的DataTemplate?
How do I implement row recycling? 如何实施行回收? Will I need to add bindings for every little parameter like border colour and alignment, and if so would this have a significant impact on performance?? 我是否需要为每个小参数(如边框颜色和对齐方式)添加绑定,如果这样会对性能产生重大影响?
Any pointers will definitely be appreciated. 任何指针肯定将不胜感激。 (I'm more at home in Android/Java and c# is an exciting new world for me) (我在Android / Java中更在家,而c#对我来说是一个令人兴奋的新世界)
Cheers, 干杯,
Peter. 彼得
WinRT does not really have support for representation of hierarchical data on a single screen. WinRT实际上并不支持在单个屏幕上表示分层数据。 If you look at how file picker is implemented - you need to dig into subfolders one by one and then go back the same way. 如果您查看文件选择器的实现方式,则需要一个一个地深入子文件夹,然后以相同的方式返回。
If your hierarchy is complicated, but relatively flat - using DataTemplates might be enough, though for Metro apps - you do not really want your hierarchy to be complicated and you might want to try to think how to make it easier to be easily consumed in the touch centric UI. 如果您的层次结构很复杂,但是相对平坦-使用DataTemplates可能就足够了(尽管对于Metro应用程序而言)-您实际上并不希望您的层次结构很复杂,并且您可能想尝试如何使它更易于在数据库中轻松使用。触摸式用户界面。
What do you mean by row recycling? 行回收是什么意思? A ListView or ListBox uses a VirtualizingStackPanel as its ItemsPanel by default and virtualizes rows or columns automatically. 默认情况下,ListView或ListBox使用VirtualizingStackPanel作为其ItemsPanel并自动虚拟化行或列。 If you want anything more custom - you might need to implement your own ItemsControl subclass instead. 如果您想要更多自定义的内容,则可能需要实现自己的ItemsControl子类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.