void RefreshAllNodes()
 {
     foreach (var page in allPages)
     {
         page.RefreshUI();
     }
     ContentConverterProperties.SetContentConverterVersion(appSettingsDlg, ++converterVersion);
 }
Beispiel #2
0
        public void Show(Guid?guid, Window ownerWindow)
        {
            LastSelectedGuid = guid;

            allPages = CreateSettingsPages();
            Debug.Assert(allPages.Any(a => a.Page.Guid == rootGuid));
            rootVM = CreateRootVM(allPages);
            if (rootVM.Children.Count == 0)
            {
                return;
            }

            pageContext.TreeView = CreateTreeView(rootVM);

            appSettingsDlg             = new AppSettingsDlg();
            appSettingsDlg.DataContext = this;
            InitializeKeyboardBindings();

            ContentConverterProperties.SetContentConverter(appSettingsDlg, this);
            ContentConverterProperties.SetContentConverterVersion(appSettingsDlg, converterVersion);
            appSettingsDlg.Owner = ownerWindow ?? throw new ArgumentNullException(nameof(ownerWindow));

            AppSettingsPageVM selectedItem = null;

            if (guid != null)
            {
                selectedItem = allPages.FirstOrDefault(a => a.Page.Guid == guid.Value);
            }
            if (selectedItem == null)
            {
                selectedItem = rootVM.Children.FirstOrDefault();
            }
            if (guid == null && selectedItem != null)
            {
                selectedItem = selectedItem.VisiblePage;
            }
            if (selectedItem != null)
            {
                pageContext.TreeView.SelectItems(new[] { selectedItem });
            }

            bool saveSettings = appSettingsDlg.ShowDialog() == true;

            LastSelectedGuid = (pageContext.TreeView.SelectedItem as AppSettingsPageVM)?.VisiblePage.Page.Guid;

            var appRefreshSettings = new AppRefreshSettings();

            if (saveSettings)
            {
                foreach (var page in allPages)
                {
                    if (page.Page is IAppSettingsPage2 page2)
                    {
                        page2.OnApply(appRefreshSettings);
                    }
                    else
                    {
                        page.Page.OnApply();
                    }
                }
            }

            foreach (var page in allPages)
            {
                page.Page.OnClosed();
            }

            if (saveSettings)
            {
                foreach (var listener in appSettingsModifiedListeners)
                {
                    listener.Value.OnSettingsModified(appRefreshSettings);
                }
            }

            // Prevent a memory leak in SharpTreeNodeProxy. This will remove all bindings and
            // remove the ValueChanged handlers from the instance stored in a static field.
            pageContext.TreeView.Root.Children.Clear();
        }
        public void Show(Guid?guid, Window ownerWindow)
        {
            if (ownerWindow == null)
            {
                throw new ArgumentNullException(nameof(ownerWindow));
            }
            LastSelectedGuid = guid;

            allPages = CreateSettingsPages();
            Debug.Assert(allPages.Any(a => a.Page.Guid == rootGuid));
            rootVM = CreateRootVM(allPages);
            if (rootVM.Children.Count == 0)
            {
                return;
            }

            currentContextVM.TreeView = CreateTreeView(rootVM);

            var selectedItem = (guid != null ? allPages.FirstOrDefault(a => a.Page.Guid == guid.Value) : null) ?? rootVM.Children.FirstOrDefault();

            if (selectedItem != null)
            {
                currentContextVM.TreeView.SelectItems(new[] { selectedItem });
            }

            appSettingsDlg             = new AppSettingsDlg();
            appSettingsDlg.DataContext = this;
            InitializeKeyboardBindings();

            ContentConverterProperties.SetContentConverter(appSettingsDlg, this);
            ContentConverterProperties.SetContentConverterVersion(appSettingsDlg, converterVersion);
            appSettingsDlg.Owner = ownerWindow;
            bool saveSettings = appSettingsDlg.ShowDialog() == true;

            LastSelectedGuid = (currentContextVM.TreeView.SelectedItem as AppSettingsPageVM)?.Page.Guid;

            var appRefreshSettings = new AppRefreshSettings();

            if (saveSettings)
            {
                foreach (var page in allPages)
                {
                    var page2 = page.Page as IAppSettingsPage2;
                    if (page2 != null)
                    {
                        page2.OnApply(appRefreshSettings);
                    }
                    else
                    {
                        page.Page.OnApply();
                    }
                }
            }

            foreach (var page in allPages)
            {
                page.Page.OnClosed();
            }

            if (saveSettings)
            {
                foreach (var listener in appSettingsModifiedListeners)
                {
                    listener.Value.OnSettingsModified(appRefreshSettings);
                }
            }
        }