Display properties of the ListBox.ItemsSource

后端 未结 2 1133
南旧
南旧 2020-12-04 02:20

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 i

相关标签:
2条回答
  • 2020-12-04 03:01

    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>
    
    0 讨论(0)
  • 2020-12-04 03:06

    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.

    0 讨论(0)
提交回复
热议问题