动态创建列表框并添加自定义列表项 [英] Creating Listbox dynamically and adding Custom List Item
问题描述
根据项目要求,我必须在运行时创建所有控件。所以我无法在XAML中创建它。
UI需要在运行时使用自定义项创建一个列表框。列表框自定义项可能有两行文本,一个图像,可能还有一个复选框。
我是WP7的新手。根据我的调查到现在为止,我所能找到的是在XAML中创建的控件,然后在cs文件中完成数据绑定。
但是根据要求,我需要在所有控件中创建代码背后。
其中一个链接有一些代码来创建数据模板并将其添加到列表框。
链接 - > http://stackoverflow.com/questions/248362/how-do-i-build-a-datatemplate-in-c-sharp-code
但是,在SDK中不推荐。我也找不到
FrameworkElementFactory
如果有人有任何解决方案,请建议。
提前致谢。
请查看以下链接。
WPF中的自定义列表框示例
http://www.codeproject.com/KB/WPF/CustomListBoxLayoutInWPF.aspx
Hi,
As per the project requirement, I have to create all the controls at runtime. So I cannot create it in XAML.
The UI requires a listbox to be created at runtime with custom Items. Listbox Custom Item might be having 2 lines of text, an image and probably a checkbox.
I am new to WP7. As per my investigation till now all I could find was controls created in XAML and then data binding done in cs file.
But as per the requirement, I need to do all the controls creation in code behind.
One of the link has some code to create data template and add it to listbox.
Link--> http://stackoverflow.com/questions/248362/how-do-i-build-a-datatemplate-in-c-sharp-code
However, in SDK it is not recommended. Also I could not find
FrameworkElementFactory
Please suggest if anybody has any solutions.
Thanks in advance.
please check below link.
Custom ListBox Sample in WPF
http://www.codeproject.com/KB/WPF/CustomListBoxLayoutInWPF.aspx
这篇关于动态创建列表框并添加自定义列表项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!