1
我使用AvalonDock,我會序列化和反序列化我的佈局。但回調(我使用ContentId創建正確對象的實例)並不總是被調用。出於這個原因,加載不能正常工作。我試圖添加一個「try-catch」,但沒有拋出異常。LayoutSerializationCallback不被調用
這是我的代碼:
`VAR layoutSerializer =新XmlLayoutSerializer(經理);
layoutSerializer.LayoutSerializationCallback += (s, e) =>
{
MyClass item;
if (items.TryGetValue(e.Model.ContentId, out item))
{
e.Content = item;
var tool = item as IMyClassToolApp;
var anchorable = e.Model as LayoutAnchorable;
var document = item as IMyClassDocumentApp;
var layoutDocument = e.Model as LayoutDocument;
if (tool != null && anchorable != null)
{
addToolCallback(tool);
tool.IsVisible = anchorable.IsVisible;
tool.IsSelected = e.Model.IsSelected;
return;
}
if (document != null && layoutDocument != null)
{
addDocumentCallback(document);
// Nasty hack to get around issue that occurs if documents are loaded from state,
// and more documents are opened programmatically.
layoutDocument.GetType().GetProperty("IsLastFocusedDocument").SetValue(layoutDocument, false, null);
document.IsVisible = true;
document.IsSelected = layoutDocument.IsSelected;
return;
}
}
e.Cancel = true;
};
try
{
layoutSerializer.Deserialize(stream);
}
catch
{
return false;
}`
謝謝你的幫忙!
我的文件沒問題,我一步一步地調試代碼,並且「Deserialize」沒有拋出異常。 –
發佈更多詳細信息會更好。代碼的更多片段。例如配置文件的內容。讓所有的LayoutAnocorables和LayoutDocuments都是他們的ID? – Jofta
我用我的代碼更新了這個問題... –