'Notifying UI once the reference of an Object is changed [closed]

I am trying to bind the selected part from a part list that is inside an object as an ObservableCollection.

<UserControl.DataContext>
        <MultiBinding Converter="{StaticResource getPartConverter}">
            <Binding Path="PartType" ElementName="PartDisplayUserControl"/>
            <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:MainWindow}" Path="ViewModelForParts"/>
        </MultiBinding>
</UserControl.DataContext>

Once the PartList (ObservableCollection) changes it is not triggering the Converter (getPartConverter). But once the PartType changes, it triggers the converter and finds the correct part. How can I trigger the converter once the part list is changed?

The code for the ViewModelForParts is as follows:

public class PartConfiguratorViewModel : PropertyChangedViewModelBase
    {
        private ObservableCollection<PartData> partList;
        public ObservableCollection<PartData> PartList 
        { 
            get => partList;
            set => SetField(ref partList, value); 
        }

        public PartConfiguratorViewModel()
        {
            PartList = new ObservableCollection<PartData>();
        }
    }

Note: The setField command has the Property Change event. Also, all the properties inside the PartData Object have the same event as well.



Solution 1:[1]

You should bind to a property that actually gets set when the collection is updated, such as for example the Count property:

<Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=local:MainWindow}"
    Path="ViewModelForParts.Count"/>

Binding to the collection property itself will only trigger the converter if you set the PartList property to another collection (which defeats the purpose of using an ObservableCollection<T> over another kind of collection that doesn't raise the INotifyCollectionChanged event)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mm8