I am writing a WPF control for my application, wrapping a ListBox and several other elements.
The ListBox has a new ItemTemplate that presents four pieces of information for each item in my list. I can hard-code each of the four bindings to specific properties in my list items, and they display normally.
However, I want my UserControl to be a little more flexible.
In ListBox and ComboBox there is a DisplayMemberPath property (inherited from ItemsControl), which seems to โinjectโ the corresponding property binding into a standard ItemTemplate.
How to achieve the same result using my user control?
I would like to configure four new properties to enable the display of information:
public string LabelDisplayPath { get; set; }
public string MetricDisplayPath { get; set; }
public string TitleDisplayPath { get; set; }
public string SubtitleDisplayPath { get; set; }
Overview of ItemsControl.DisplayMemberPath with a reflector, it seems to go down the rabbit hole, I could not understand how it works.
Also, if I'm completely unaware - and there is another, more "WPF" method that I should use instead, point me in that direction.
Update
Here is an explanation of what I'm trying to achieve.
The ListBox inside my user control displays four pieces of information for each item: Label, Title, Subtitles and Metric
In one place, I want to use this control to display a list of problems. Each problem is as follows:
public class Issue {
public string Code { get; set; }
public string Description { get; set; }
public string Priority { get; set; }
public string Reporter { get; set; }
}
:
Code --> Label
Description --> Title
Reporter --> Subtitle
Priority --> Metric
, , UserControl. :
public class Post {
public DateTime PostedOn { get; set; }
public string Title { get; set; }
public string Teaser { get; set; }
public int CommentCount { get; set; }
}
:
PostedOn --> Label
Title --> Title
Teaser --> Subtitle
CommentCount --> Metric
, , , UserControl . , UserControl .