I would like to created listbox with ItemsSource and SelectedItem binding on model object.
The Binding is done as following :
<ItemsControl ItemsSource="{Binding Persons}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" Width="150" />
<ListBox
BorderThickness="0"
Background="Transparent"
Margin="0 1"
ItemsSource="{Binding DataContext.Skills,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Mode=OneWay}"
SelectedItem="{Binding MasterSkill, Mode=TwoWay}"
SelectionMode="Single"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
On the first load it works, the value are selected with the default registered data.
The problem appear after switch/reload the current viewModel UI. When i come back to the ViewModel SelectItem is null.
The values seems update on/after leaving the UI (on the unload). The problem disappear when i use delay(>0) property or when i set UpdateSourceTrigger to LostFocus
I created an exemple of my problem on Github => here (In the exemple you have to go on "Manage Skills" windows and switch to "Manage project" to finally return to the skills)
I think the UI thread call the event propertyChanged when the control is unload or destroyed... but i don't really know how to avoid this problem.
Thanks a lot for your help.
NavigateTomethod andGoToProj&GoToSkillsproperties. Everytime, you are creating a new object of the ViewModel instead of returning the old initialized object. So since, you are returning new object a new View is created everytime that's means you will loose the state of previous instance of view of same type. - user1672994