0
我有我在構建代碼的窗口,並顯示:新窗口中打開在當前
Window wndViewer = new Window();
wndViewer.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0x31, 0x31, 0x31));
wndViewer.WindowState = WindowState.Maximized;
wndViewer.Width = 1024;
wndViewer.Height = 768;
Grid grd = new Grid();
wndViewer.Title = "<Removed>";
Viewer vw = new Viewer(); // This is a UserControl
vw.StudyDate = ((StudyItem)sender).StudyDate.ToString("MM/dd/yyyy");
vw.PatientName = ((StudyItem)sender).PatientName;
vw.PatientId = ((StudyItem)sender).OwnerName;
vw.Margin = new Thickness(3, 30, 3, 3);
vw.StudyInstance = ((StudyItem)sender).ItemStudy;
grd.Children.Add(vw);
wndViewer.Content = grd;
refreshTimer.Stop();
wndViewer.Tag = vw.StudyInstance;
wndList.Add(wndViewer); // List<Window> of all the windows opened this way.
DependencyObject dpParent = LogicalTreeHelper.GetParent(this);
while (dpParent != null && dpParent.GetType() != typeof(Window))
{
dpParent = LogicalTreeHelper.GetParent(dpParent);
}
wndViewer.Owner = (Window)dpParent;
wndViewer.ShowActivated = true;
wndViewer.Show();
的問題是,我需要這個窗口中顯示當前窗口的頂部,它總是在當前窗口下出現。我已經嘗試了幾種解決方案:
wndViewer.BringIntoView();
導入和調用:
[DllImport("User32.dll")]
public static extern Int32 SetForegroundWindow(int hWnd);
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
所以,我敢肯定,我在這裏忽視的東西。謝謝你的幫助!
〜〜的md5sum
這似乎已經做了伎倆......但是,它有點「駭人聽聞」,因爲現在動態窗口必須從主窗口移出才能返回到主窗口。儘管現在它肯定會工作! – 2009-11-06 20:06:56
在這種情況下,「this」不是一個窗口,而是一個UserControl,所以我得到了邏輯父窗口並使用它,因爲owner屬性只接受一個窗口。此外,Window類沒有可公開訪問的Initialise方法,因此必須特定於AboutBox。 – 2009-11-06 20:51:05
(hackish或不)重置vw.Loaded事件處理程序中的標誌具有我在此需要的確切效果。窗戶出現在前面,但並不是始終強迫自己前行。 – 2009-11-06 20:57:21