在 C# 中显示 WPF 对象列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22681184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 11:21:59  来源:igfitidea点击:

Display List of WPF Objects in C#

c#wpfxaml

提问by OmegaNine

This is hard to explain, and I am still pretty novice so I am apologies in advance.

这很难解释,我仍然是新手,所以我提前道歉。

Is there a way to take a WPF XAML document and display a list of them in a listBox?

有没有办法获取 WPF XAML 文档并在列表框中显示它们的列表?

Like if I wanted to make a contact list. I could create a .xaml file with the stuff I want (Icon, String to hold name, icon to show cell/home/pager) then call in to a list as if it were a class that I am making an instance off to fill the list.

就像我想制作联系人列表一样。我可以用我想要的东西(图标、保存名称的字符串、显示单元格/主页/寻呼机的图标)创建一个 .xaml 文件,然后调用一个列表,就好像它是一个类,我正在创建一个实例来填充列表。

Any help, even just a name, pattern or keyword to lookup, would be extremely helpful.

任何帮助,甚至只是查找的名称、模式或关键字,都会非常有帮助。

Thanks, Dane

谢谢,戴恩

回答by nvoigt

What you are looking for is called an ItemTemplate. It's a description of what each item in your collection should look like in your view.

您要查找的内容称为ItemTemplate. 它描述了您的集合中的每个项目在您的视图中应该是什么样子。

A nice tutorial can be found here.

一个不错的教程可以在这里找到。