
I have a view which has a docksite attached. When I change my DataContext the ToolWindows states are lost. How can I retain the state between DataContext updates? I have the following code which attempts to save the state when the docksite datacontext is changed. The ToolWindows have the correct sizes however when I serialize out the state the XML is incorrect and shows the initialized values.
Even if I trap the _dockSite.WindowsClosing += _dockSite_WindowsClosing event and try to serialize out the values are incorrect. The only time the serialization is correct is when I fully unload the view, although I a haven't tired adding a callback from my View Model because I'd really like to avoid a callback reference from from my viewmodel to my code beind.
public void SaveDockState()
{
if (_dockSite == null)
return;
if (_dockSite.ToolWindows.Count == 0)
return;
if (LastTimeSaved != null && DateTime.Now - LastTimeSaved < TimeSpan.FromSeconds(1))
return;
string xml = s.SaveToString(_dockSite);
XFile.StringToFile(xml, StateFilePath);
LastTimeSaved = DateTime.Now;
}
After trying out a slew of event handlers I think I have this working using the WindowsClosing and WindowsOpening along with a variable that checks to see if the the docksite is loading state so there isn't a recursion bug on load.
[Modified 2 years ago]