Coming from a WinForms background, I'm a little surprised to see that most (if not all) of the field-related properties for things like ItemsControl
s in WPF lack any sort of dropdown list for selecting fields.
For example, when using a ComboBox
, if I bind the ItemsSource
to a strongly-typed collection on my ViewModel in the designer, the DisplayMemberPath
and ValueMemberPath
properties require that I type in the names of the appropriate fields manually. My previous WinForms experience is that when binding to a strongly-typed list (in particular, a source that implements ITypedList
), I would be given a dropdown of available fields so that there's no chance of fat-fingering the field name.
Am I doing something wrong here, or is this just not something that's been baked into WPF yet?
I know that this functionality was provided by the ITypedList
interface in WinForms, but my understanding was that the System.ComponentModel
approach to binding (PropertyDescriptor
s, ITypedList
, IBindingList
, and IListSource
) were not used in WPF. Things like data grids seem to have no problems obtaining a list of fields to create columns, so I'm just curious if (and/or why) these properties that are intended to represent property names do not provide the same level of functionality.
In WPF properties like DisplayMemberPath
and ValueMemberPath
aren't just properties - an example might be:
<ComboBox
DisplayMemberPath="Addresses[0].Line1"
ValueMemberPath="Address[0].Id"
SelectedValue="{Binding Path=FavoriteAddressId}"
...
/>
If the designer properties only let you select from a list of properties, you'd be missing out on some pretty useful features. But you are right that providing a list in addition to being able to type it in would be useful.
There's always been a power struggle between WPF's binding system, which is quite dynamic, and the team's vision for tooling which requires a certain amount of rigidity. This is one of those cases that probably fell in the gap.
Edit: PropertyDescriptors
, IBindingList
and some other components of Windows Forms binding are used in WPF too - for example, my MicroModels library relies on PropertyDescriptors to work, and is built for WPF. Silverlight however doesn't support many of these.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With