View Model Binding to TabControl Items
description
In the attached WPF application demonstrates an issue with tab pages.
I have a main viewmodel that has a property with a list of data objects called Items and a SelectedItem property. The main view has a DataGrid for showing the items and a TabControl containing three User Controls to show the details. Caliburn Micro has bound The DataGrid to the Items property and the selected item to the SelectedItem property of the view model. The user controls are bound in xaml to the selected item, the text boxes inside the user controls are bound by Caliburn Micro to the belonging data properties.
If I e.g. select the first ten items in the list one after one the following happens:
The user control in the visible tab item is updated after each change of the selection, this is good. When I select the second tab things go wrong. The SelectedItem property is set ten times, this happens in the order the items where selected. If I switch to the second tab the same happens. It event gets worse if a third tab is added. In this case the number of sets increases after each change of tab item. I have noticed that this only happens when there are multiple user controls in the tab control that have bindings to properties of the selected item.
Reproduce as follows:
Open, build and run solution. A window will open.
Select a number of rows one after one in the datagrid. Press the reset button and switch between the tab pages. The Id lists shows the id’s of the objects that are set to the SelectedItem property and get from the SelectedItem property