ListBox.ItemsSource 的显示属性

发布于 2024-08-09 10:06:06 字数 501 浏览 3 评论 0原文

我是 WPF 新手。我有一个 ListBox,其 ItemSource 设置为 WorkItemCollection。 (WorkItem 的集合 对象。)

显示列表时,仅显示每个对象的类型 (Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem)。有没有办法让列表显示WorkItem.Title?

I am new to WPF. I have a ListBox that has its ItemSource set to a instance of WorkItemCollection. (A collection of WorkItem objects.)

When the list is displayed it only displays the type of each object (Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem). Is there a way to make the list display WorkItem.Title?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-08-16 10:06:06

你有两个选择。

最简单的方法是设置 DisplayMemberPath将 ListBox 的 属性设置为“Title”。

如果您不仅想设置显示的内容,还想设置用于显示它的控件类型,那么您可以设置 ListBox 的 ItemTemplate

对于您的目标是什么,我会推荐第一个选项。

You have two options.

The simplest method is to set the DisplayMemberPath property of your ListBox to "Title".

If you want to set not only what gets displayed, but the type of control that is used to display it, then you would set the ListBox's ItemTemplate.

For what your goal is, I would recommend the first option.

咋地 2024-08-16 10:06:06

您可以在 ListBoxItemTemplate 属性上设置 DataTemplate

<ListBox ItemSource="{Binding}">
  <ListBox.ItemTemplate>
    <DataTemplate DataType="tfs:WorkItem">
      <StackPanel>
        <TextBlock Text="{Binding Title}" />
        <!-- Others -->
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

You can set a DataTemplate on the ItemTemplate property of the ListBox:

<ListBox ItemSource="{Binding}">
  <ListBox.ItemTemplate>
    <DataTemplate DataType="tfs:WorkItem">
      <StackPanel>
        <TextBlock Text="{Binding Title}" />
        <!-- Others -->
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文