I use MVVM-Light. In my XAML I have the following binding in a TreeView.
<TreeView Grid.Row="1"
ItemsSource="{Binding Model.Root.ChildPages, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
The Model property in the VM looks as follows.
public TreeModel Model
{
get { return model_; }
set
{
Set(nameof(Model), ref model_, value);
}
}
TreeModel and TreeModel.Root are both ObservableObjects. TreeModel.Root.ChildPages is an ObservableCollection.
(I am actually not changing the currently binded objects, but I set a completely new Model so that I in fact use observable objects as my model should not make any difference but I thought it was worth to mention)
When setting my Model property, my TreeView does not update / showing the new TreeModel. The Set() function from MVVM Light should call RaisePropertyChanged() internally as far as I am aware.
The ViewModel that the View binds to is derived from a MyViewModelBase class which is derived from MVVM Light's ViewModelBase class. The Model property is defined in the MyViewModelBase class.
What am I missing, why does the View not get refreshed? How to solve it?
When setting the Model property from the ViewModels constructor, it will be displayed as expected by the TreeView, it is only successive calls from outside the control to the Model property that does not affect the TreeView. I have debugged and confirmed the line in the setter
Set(nameof(Model), ref model_, value);
really gets called.
Set(ref model_, value);
. As to your actual issue, you need to provide more details about how you set theDataContext
etc. – mm8Model
property to a new object. Make sure that you are modifying the data bound instance of the view model. – mm8