예제 #1
0
파일: Program.cs 프로젝트: danwalmsley/Dock
        static void Main(string[] args)
        {
#if !NET461
            Thread.CurrentThread.TrySetApartmentState(ApartmentState.STA);
#endif
            try
            {
                var   vm      = new MainWindowViewModel();
                var   factory = new MainWindowDockFactory();
                IDock layout  = null;

                string path = DockSerializer.GetBasePath("Layout.json");
                if (DockSerializer.Exists(path))
                {
                    layout = DockSerializer.Load <DockRoot>(path);
                }

                BuildAvaloniaApp().Start <MainWindow>(() =>
                {
                    // NOTE: Initialize layout after main window was created so child windows can be created.
                    vm.Factory = factory;
                    vm.Layout  = layout ?? vm.Factory.CreateLayout();
                    vm.Factory.InitLayout(vm.Layout, vm);
                    return(vm);
                });

                vm.Layout.CurrentView.HideWindows();
                DockSerializer.Save(path, vm.Layout);
            }
            catch (Exception ex)
            {
                Print(ex);
            }
        }
예제 #2
0
        public void Serialization0()
        {
            DockControlViewModel dockControl = CreateDockLayout();

            // Serialize layout.
            var xElement1 = DockSerializer.Save(dockControl);

            // Make some changes.
            dockControl.DockStrategy.Close(dockControl.FloatWindows[0]);

            // Deserialize and serialize again.
            DockSerializer.Load(dockControl, xElement1);
            var xElement2 = DockSerializer.Save(dockControl);

            // We want to compare the two created XMLs. But first we must remove the
            // LastActivation="..." entries, because they will not match.
            var string1 = xElement1.ToString();
            var string2 = xElement2.ToString();
            var r       = new Regex(@"LastActivation="".*""");

            string1 = r.Replace(string1, string.Empty);
            string2 = r.Replace(string2, string.Empty);

            Assert.AreEqual(string1, string2);
        }
예제 #3
0
        /// <summary>
        /// Loads the docking layout.
        /// </summary>
        /// <param name="storedLayout">The stored layout.</param>
        /// <inheritdoc cref="DockSerializer.Load"/>
        public void LoadLayout(XElement storedLayout)
        {
            try
            {
                DockStrategy.Begin();

                var oldItems = Items.ToList();
                DockSerializer.Load(this, storedLayout);
                var newItems = Items.ToList();

                // Screen conduction for items closed in Load().
                foreach (var dockTabItem in oldItems.Except(newItems))
                {
                    // IActivatable
                    (dockTabItem as IActivatable)?.OnDeactivate(true);

                    // IScreen
                    var screen = dockTabItem as IScreen;
                    if (screen != null)
                    {
                        screen.Conductor = null;
                    }
                }
            }
            finally
            {
                DockStrategy.End();
            }
        }
예제 #4
0
        private void OnDeserialize(object sender, RoutedEventArgs e)
        {
            var xElement = XElement.Parse(TextBox0.Text);

            DockSerializer.Load(DockControlViewModel, xElement);
            xElement = DockSerializer.Save(DockControlViewModel);

            TextBox1.Text = xElement.ToString();
        }
 private void OnLoadLayout(object sender, RoutedEventArgs eventArgs)
 {
     DockSerializer.Load(DockControlViewModel, XDocument.Load("DockControlTest.Layout").Root);
 }