How to implement DisplayMemberPath for my Wpf UserControl?
- by Bevan
I'm writing a WPF User Control for my application, wrapping a ListBox and a few other items.
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 on my list items and they display fine.
However, I want my UserControl to be a bit more flexible.
On ListBox and ComboBox there is a property DisplayMemberPath (inherited from ItemsControl) that seems to "inject" the appropriate property binding into the standard ItemTemplate.
How do I achieve the same result with my user control?
I'd like to set up four new properties to allow configuration of the information displayed:
public string LabelDisplayPath { get; set; }
public string MetricDisplayPath { get; set; }
public string TitleDisplayPath { get; set; }
public string SubtitleDisplayPath { get; set; }
Reviewing ItemsControl.DisplayMemberPath with Reflector seems to go down the rabbit hole, I haven't been able to fathom how it works.
Also, if I'm completely off course - and there's another, more "WPF" technique that I should be using instead, please point me in that direction.