Q:

How to create ObservableCollection sorted by item's property and emitting CollectionChanged when item's property changes

I have a list of controls, where each control has ZIndex property:
class WizardControl : INotifyPropertyChanged
{
    public int ZIndex { get; set; /* set emits PropertyChanged event */}
}

class WizardStep
{
    ObservableCollection<WizardControl> Controls { get; set; }
}

class Wizard
{
    ObservableCollection<WizardStep> Steps { get; set; }
}

I also have a TreeView using HierarchicalDataTemplate, where each WizardStep has a tree-node with all WizardControl as tree leaves.
Now I would like to sort the controls by their ZIndex. I found a solution using custom Converter (http://stackoverflow.com/a/5730402/69868), which works fine as long as ZIndex does not change.
When the ZIndex changes, the sorted CollectionView does not emit CollectionChanged event and the GUI does not pick the change of order.
My question: how to create a sorted collection that will emit correct events when items are reordered due to change in sort-by values?

A:

For this you must use CollectionView wrapped around your ObservableCollection with CollectionView.SortDescriptions.Add(new SortDescription(ZIndex)).
This way whenever the ZIndex of any item inside the observable collection changes, it would acquire the correct sort position on the GUI automatically.

