Dee J. Doena Dee J. Doena - 1 month ago 24
C# Question

MVVM: Force ComboBox labels to refresh

I have a ComboBox bound to an

ObservableCollection<IDrive>


The problem is that
IDrive
does not support
INotifyPropertyChange
nor should it.

While the number of elements in my ComboBox is fixed and does not change, the labels shown in the ComboBox can and will change.

How do I get these labels to update?

Firing
PropertyChanged
on my ObservableCollection does not refresh the content of the labels but it does reset the
SelectedItem
which is a side-effect I don't even want.

Here's my current XAML:

<ComboBox Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="4"
ItemsSource="{Binding Drives}" SelectedItem="{Binding SelectedDrive}"
IsSynchronizedWithCurrentItem="True" DisplayMemberPath="Label"
Margin="5,5,5,5" VerticalAlignment="Center" />


Label
being the property in my
IDrive
interface

Answer

You will need to wrap the items in a DriveViewModel : INotifyPropertyChanged and have that repeat the relevant properties. And somehow trigger the changed event from that.

On second thought, I'm not sure if DisplayMemberPath picks up on this. You'll probably need an ItemTemplate as well.