Layout is lost when data context is updated

Docking/MDI for WPF Forum

Posted 2 years ago by Michael Janulaitis - Corner Bowl Software
Version: 22.1.0
Avatar

I have a combobox which allows a user to select different view models.  The view below is a docksite and the datacontext is set the the combobox's selected item.  When the user selects the combobox the toolwindows locations are all lost and reset to the right pane.   All inside content is displayed with the new selected view model.  The expected behaviour is all toolwindow locations are left as is.  I have verified the docksite container is not receiving a new loading event.  The only event I see fired that I've looked for is datacontext changed.  The toolwindows are created with bindings.

[Modified 2 years ago]

Comments (5)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

Without knowing more detail, it's difficult to know what's going on here.  If you are using our product in a MVVM setup, and are effectively changing the items sources due to your data context changes, then perhaps that is resetting the layout.  You might need to serialize the layout before you do this change, then deserialize it after.

If that doesn't help, please make a new simple sample project that shows the issue and send that to our support address.  Reference this thread in your email and remove the bin/obj folders from the .zip you send so it doesn't get spam blocked.  Thanks!


Actipro Software Support

Posted 2 years ago by Michael Janulaitis - Corner Bowl Software
Avatar

I tried to serialize when the datacontext was changed however the toolwindows were already gone and my serialized output was blank.  If I were to just use my last layout then it would be incorrect if the user made changes.

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

It's hard to offer suggestions without a working sample project to see and debug.  But if it's a timing thing, perhaps you need to not directly bind the DataContext to the ComboBox selection, and instead have some intermediate property.  Then when that property changes, do the layout save, update DataContext, and then layout load.


Actipro Software Support

Posted 2 years ago by Michael Janulaitis - Corner Bowl Software
Avatar

I have created a project that shows off two bugs.  First the tool window losing position when the data context is updated then second the tool windows are totally lost from the view when selecting back on a previously selected item.

Thanks for looking into this.

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

Thank you for the sample.  It helps illustrate the scenario very well.

What's happening is that you are effectively updating the DockSite.ToolItemsSource property as the ComboBox selection updates but nothing is saving the layout before the update.  When the ToolItemsSource changes, all the docking windows in the layout are closed since it thinks you want a brand new layout.  As the second ComboBox item is selected, it's a brand new default layout for these new tool window view-models.  When you flip back to select the first ComboBox item, it loads the tool window view-models from before, but the IsOpen property is false on all of them from when they were closed earlier.  Thus the layout appears blank.

There are two different approaches we can take here, but you need to let us know which one is more appropriate for your app.

1) You mentioned wanting to keep the tool windows in the same place.  If you want to keep the exact same tool windows, then you should not be binding them to view-models in your ComboBoxAvailableItemViewModel that changes, and should have the ToolItemsSource view-models at a higher level that doesn't change.  That is the easiest solution, since if ToolItemsSource never changes (e.g. you use a Binding without inherited data context), the layout won't change.

or

2) You want different tool window view-models in each ComboBox selection.  This will cause the layout to change when the ComboBox selection updates but we can add code to serialize the layout before and restore after.  

2a) This is #2 where you want your Red, Green, Blue tool windows to end up in the exact same location they were at before any changes to the ComboBox selection.  But if you want this, then it seems like #1 is a better, cleaner approach.

2b) This is #2 but where each ComboBoxAvailableItemViewModel will store its own unique layout.  So when you have the first ComboBoxAvailableItemViewModel selected and switch to the second one, it will serialize the first's layout and store it in the first ComboBoxAvailableItemViewModel.  Then the second one will load the second ComboBoxAvailableItemViewModel's previously-serialized layout (if known), and so on.

Let us know if you are looking for #1, #2a, or #2b.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.