关于.net列表框的问题 [英] Question about .net listbox

查看:79
本文介绍了关于.net列表框的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://msdn.microsoft.com/en-us/library /system.windows.controls.itemscontrol.items



这是关于ItemsControl.Items的文档。在这个doc中,listbox可以显示矩形,椭圆甚至一个面板,但是当我使用listbox时,它只能显示字符串。我怎么能解决这个问题,非常感谢!

http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.items

this is the document about ItemsControl.Items.In this doc,listbox can show rectangle、ellipse even a panel,but when i use listbox,it only can show strings.How can i solve this,thanks very much!

推荐答案

请看我对这个问题的评论。解决方案1几乎没用,它没有解释这些事情是如何完成的。



通常,使用数据模板,通常带有绑定。在您的情况下,您可能不会使用绑定,但您需要使用一些模板。



请参阅此MSDN文章:http://msdn.microsoft.com/en-us/library/ms742521%28v=vs.110% 29.aspx [ ^ ]。



在本文中,请查看定义一个简单的DataTemplate部分及其中最简单的代码示例,关于 ListBox ,如你所知。



这是更复杂的例子,项目模板单独定义: http://msdn.microsoft.com/en-us/library/ms750821%28v = vs.85%29.aspx [ ^ ]。



一般来说,你需要先学习模板和装订,然后思考如何将这些技巧应用到你的案例中。







另请参阅我对解决方案1的最后评论。它应该解释为什么不能按照那里提到的方式向视觉树添加一些视觉效果。要深入研究这个问题,你需要了解WPF中视觉和逻辑树的分离:

http://msdn.microsoft.com/en-us/library/ms753391%28v=vs.110%29.aspx [ ^ ]。



这件事是物品控制的基础,特别是。



-SA
Please see my comment to the question. Solution 1 is pretty much useless, it does not explain how such things are really done.

Usually, data templating is used, usually with binding. In your case, you may probably not use binding, but you will need to use some templates.

Please see this MSDN article: http://msdn.microsoft.com/en-us/library/ms742521%28v=vs.110%29.aspx[^].

In this article, look at the section "Defining a Simple DataTemplate" and the simplest code sample in it, which is about ListBox, as you need.

This is more complex example with item template defined separately: http://msdn.microsoft.com/en-us/library/ms750821%28v=vs.85%29.aspx[^].

Generally, you need first learn templating and binding and then think how to apply these techniques to your case.



Please also see my last comment to Solution 1. It should explain why cannot just add some visuals to the visual tree the way mentioned there. To dig into this issue, you would need to learn about separation of visual and logical tree in WPF:
http://msdn.microsoft.com/en-us/library/ms753391%28v=vs.110%29.aspx[^].

This matter is fundamental to the item controls, in particular.

—SA


您可以使用StackPanel作为ListBox的子级。将要显示的各种元素添加到StackPanel,而不是将其作为项目添加到ListBox ...

http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel(v = vs.110) .aspx [ ^ ]
You may use StackPanel as the child of the ListBox. Add the various elements you want to show to the StackPanel, than add it to the ListBox as item...
http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel(v=vs.110).aspx[^]


这篇关于关于.net列表框的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆