/// <summary> Create an Editor Window.</summary> public void CreateNewEditorWindow(BlogEntryEventArgs arg) { if (arg.Entry == null) { return; } var win = new EditorWindow(); win.DataContext = new EditorViewModel(arg.Entry); App app = App.Current as App; app.WindowList.Add(win); // We can't use Show() or set win.Owner = this. // Try minimized and resotre a child window then close it. An owner window minimizes itself. //win.Owner = this; //win.Show(); win.ShowInTaskbar = true; win.ShowActivated = true; win.Visibility = Visibility.Visible; win.Activate(); }
/// <summary> Create or BringToFront an Editor Window.</summary> public void CreateOrBringToFrontEditorWindow(BlogEntryEventArgs arg) { if (arg.Entry == null) { return; } string id = arg.Entry.ID; App app = App.Current as App; // The key is to use app.WindowList here. //foreach (var w in app.Windows) foreach (var w in app.WindowList) { if (!(w is EditorWindow)) { continue; } if ((w as EditorWindow).DataContext == null) { continue; } if (!((w as EditorWindow).DataContext is EditorViewModel)) { continue; } if (id == ((w as EditorWindow).DataContext as EditorViewModel).ID) { //w.Activate(); if ((w as EditorWindow).WindowState == WindowState.Minimized || (w as Window).Visibility == Visibility.Hidden) { //w.Show(); (w as EditorWindow).Visibility = Visibility.Visible; (w as EditorWindow).WindowState = WindowState.Normal; } (w as EditorWindow).Activate(); //(w as EditorWindow).Topmost = true; //(w as EditorWindow).Topmost = false; (w as EditorWindow).Focus(); return; } } var win = new EditorWindow { DataContext = new EditorViewModel(arg.Entry) }; app.WindowList.Add(win); // We can't use Show() or set win.Owner = this. // Try minimized and resotre a child window then close it. An owner window minimizes itself. //win.Owner = this; //win.Show(); win.ShowInTaskbar = true; win.ShowActivated = true; win.Visibility = Visibility.Visible; win.Activate(); }