ListBox.ItemsSource Display Properties

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

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

+3
source share
2 answers

You have two options.

The easiest way is to set the DisplayMemberPath of your ListBox to "Title".

, , , , ListBox ItemTemplate.

.

+9

DataTemplate ItemTemplate ListBox:

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

Source: https://habr.com/ru/post/1721653/


All Articles