public void SwitchWindow(string windowId) { var windows = Application.Current.Windows; for (int i = 0; i < windows.Count; i++) { var w = windows[i]; if (windowId.Equals(w.Tag)) { w.Activate(); return; } } if (windowId == "Settings") { var w = new SettingsWindow { DataContext = CreateSettingViews() }; InitWindow(w); w.Show(); w.Activate(); } var view = layout[windowId]; if (view != null) { var w = new Window { Tag = windowId, Title = localization.GetLocalized("ViewTitle", windowId) ?? windowId, Content = view.LoadContent(), }; InitWindow(w); w.Show(); w.Activate(); } }
public void SwitchWindow(string windowId) { var windows = Application.Current.Windows; for (int i = 0; i < windows.Count; i++) { var w = windows[i]; if (windowId.Equals(w.Tag)) { w.Activate(); return; } } if (windowId == "Settings") { var w = new SettingsWindow { DataContext = CreateSettingViews() }; InitializeAndShow(w); w.Show(); w.Activate(); } var windowContent = layout[windowId]?.LoadContent() ?? Compositor.Default.TryResolveView(windowId); if (windowContent != null) { var w = new ModernWindow { Tag = windowId, Title = localization.GetLocalized("ViewTitle", windowId) ?? windowId, Content = windowContent }; InitializeAndShow(w); } }
public override void Run() { Window window; try { layout = (LayoutRoot)XamlReader.Parse(layoutSetting.XamlString.Value); window = new MainWindow { MainContent = layout.MainWindow.LoadContent() }; } catch { layout = (LayoutRoot)Application.LoadComponent(new Uri("/Sakuno.ING.Shell.Desktop;component/Layout/Default.xaml", UriKind.Relative)); window = new MainWindow { MainContent = layout.MainWindow.LoadContent() }; } InitWindow(window); var app = new Application { ShutdownMode = ShutdownMode.OnMainWindowClose }; var style = new Style { TargetType = typeof(ViewPresenter), }; style.Setters.Add(new Setter(ViewPresenter.ViewSourceProperty, Views)); app.Resources[typeof(ViewPresenter)] = style; app.Resources[ViewSwitcher.SwitchActionKey] = new Action <string>(viewId => { var windows = Application.Current.Windows; for (int i = 0; i < windows.Count; i++) { var w = windows[i]; if (viewId.Equals(w.Tag)) { w.Activate(); return; } } if (viewId == "Settings") { var w = new SettingsWindow { DataContext = CreateSettingViews() }; InitWindow(w); w.Show(); w.Activate(); } var view = layout[viewId]; if (view != null) { var w = new Window { Tag = viewId, Title = localization.GetLocalized("ViewTitle", viewId) ?? viewId, Content = view.LoadContent(), }; InitWindow(w); w.Show(); w.Activate(); } }); app.Startup += (s, e) => provider.Enabled = true; app.Run(window); }