
Hello,
I'm trying save and load docking layout with MVVM.
I have changed sample program "MvvmDocumentWindows" based on this so that I can save and load layout.
layoutSerializer.DockingWindowDeserializing += (sender, args) =>
{
var dockSiteVM = (DockSiteViewModel)dockSite.DataContext;
// TODO: Make sure each docking window has a SerializationId or other info store
// that allows you to determine what kind of VM to load up here... this is a test
// of basic functionality though to show you how to load a VM-based docking window
// when deserializaing a layout
var windowVM = new Documents.GraphDocumentItemViewModel();
windowVM.IsOpen = false;
windowVM.SerializationId = args.Node.SerializationId;
dockSiteVM.DocumentItems.Add(windowVM);
args.Window = dockSite.ContainerFromDocumentItem(windowVM);
};
However, the following exception oocurred.
Would you please tell me the solution?
System.InvalidOperationException
HResult=0x80131509
Message=Specified element is already the logical child of another element. Disconnect it first
Source=PresentationFramework
スタック トレース:
at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
at System.Windows.FrameworkElement.AddLogicalChild(Object child)
at ActiproSoftware.Windows.Controls.Docking.Primitives.DockingWindowContainerBase.WfS(Object , NotifyCollectionChangedEventArgs )
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.poN(DockSite , XmlDockSiteLayout , DockHost , XmlTabbedMdiContainer )
at ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.ooW(DockSite , XmlDockSiteLayout , DockHost , Workspace , Qg , XmlTabbedMdiHost )
at ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.GoG(DockSite , XmlDockSiteLayout , DockHost , Workspace , Qg , XmlWorkspace )
at ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.foc(DockSite , XmlDockSiteLayout , DockHost , Workspace , Qg , XmlSplitContainer )
at ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.aoO(DockSite , XmlDockSiteLayout )
at ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.ApplyTo(DockSite obj)
at ActiproSoftware.Windows.Serialization.XmlSerializerBase`2.LoadFromString(String xml, TObj obj)
at ActiproSoftware.ProductSamples.DockingSamples.QuickStart.MvvmDocumentWindows.MainView.LoadLayoutMenu_Click(Object sender, RoutedEventArgs e) in C:\Users\3140361\Documents\Actipro Software\WPF-Controls\v21.1.3\SampleBrowser\ProductSamples\DockingSamples\QuickStart\MvvmDocumentWindows\MainView.xaml.cs:line 53
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at ActiproSoftware.SampleBrowser.App.Main()