Quantcast
Channel: AvalonDock
Viewing all articles
Browse latest Browse all 2690

New Post: [Version 2.0] Bug? Deserializing floating window results in two views

$
0
0

I've got a weird problem here and I'm not sure if it's a bug or a problem in my code.

i'm using the following code to serialize the layout into my app settings:

using (var memoryStream = new MemoryStream()) {new XmlLayoutSerializer(MainWindow.sharedDockingManager).Serialize(memoryStream);
	memoryStream.Seek(0, SeekOrigin.Begin);var layout = new StreamReader(memoryStream).ReadToEnd();
	Settings.Default.AvalonDockLayout = layout;
}

And this to deserialize:

string layout = Settings.Default.AvalonDockLayout;var bytes = Encoding.Default.GetBytes(layout);
MemoryStream memoryStream = new MemoryStream();
memoryStream.Write(bytes, 0, bytes.Length);
memoryStream.Seek(0, SeekOrigin.Begin);
XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(MainWindow.sharedDockingManager);
layoutSerializer.LayoutSerializationCallback += (s, e) =>
{if (!string.IsNullOrWhiteSpace(e.Model.ContentId))
		e.Content =
			Workspace.This.AvalonDockAdapter.OpenLayoutItemByContentId(
				e.Model.ContentId);
};
layoutSerializer.Deserialize(memoryStream);

Where the callback uses this helper method to get or create a viewModel:

case"CommoditySearchToolWindow":var commoditySearchToolWindowViewModel =
        Workspace.This.AvalonDockAdapter.GetAnchorableOfType(typeof(CommoditySearchToolWindowViewModel));if (commoditySearchToolWindowViewModel != null)return commoditySearchToolWindowViewModel;

    commoditySearchToolWindowViewModel = new CommoditySearchToolWindowViewModel();
    Workspace.This.AvalonDockAdapter.AddAnchorable(commoditySearchToolWindowViewModel, false);return commoditySearchToolWindowViewModel;
This works perfectly for docked AnchorablePanes, but if a pane is floating when it's serialized, upon deserialization it produces a window containing my view and hooked up to the viewmodel correctly, and another directly behind it in the z-index (the same size) with the same properties (title, etc) but no view. Clicking the X on one of the windows will hide both, and reopening one will open both again. Docking either of the floating windows to the main window will cause both to dissapear and the correct one (with the view) to dock, and then floating the now docked pane results in correction of the problem with only the one window floating.

Using version 2.0.1737.0 built from source.


Viewing all articles
Browse latest Browse all 2690

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>