I have a window that I'm building in code, and showing:
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();
The problem is that I need this window to be displayed on top of the current window, and it always comes up under the current window. I've tried several solutions:
wndViewer.BringIntoView();
Importing and calling:
[DllImport("User32.dll")]
public static extern Int32 SetForegroundWindow(int hWnd);
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
So, I'm sure I'm overlooking something here. Thanks for any help!
~md5sum~