简体   繁体   English

如何从C#中的代码动态创建ListBox项(Winrt)

[英]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件(相关的)问题在困扰着我。

  1. 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?

  2. 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.

相关问题 C#如何刷新列表框中的项目 - c# how do i refresh items in my listbox 如何通过数字C#对txt文件中的列表框项目进行排序 - How do i sort listbox items from a txt file by numbers c# C#WinRT-从后面的代码创建和修改按钮 - C# WinRT - Create and modify buttons from code behind 如何在Windows Phone 7 / C#中将项目动态添加到ListBox - How to dynamically add items to ListBox in Windows Phone 7/C# 如何在C#Windows应用商店应用(又名WinRT / Metro)中创建查询字符串? - How do I create a query string in a C# Windows Store App (a.k.a. WinRT/Metro)? 每当我单击 C# 中的按钮时,如何将 Append 项添加到另一个 Window 中的列表框? - How Do I Append Items to a Listbox in Another Window Whenever I Click a Button in C#? 如何在C#中动态创建列表框,它应该像intellisense - How to create listbox dynamically in c# .it should be like intellisense 如何使用C#检索/比较HTML列表框中的项目 - How do I retrieve / compare items in an HTML Listbox using C# 如何使用Winforms C#获取用户在列表框中选择项目的顺序 - how do I get the order in which user selected Items in Listbox using Winforms c# 如何通过单击按钮C#将列表框项目传输到文本框中 - How Do I Transfer Listbox Items Into A Textbox By Clicking A Button C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM