An application with docking capabilities can save the desktop with the positions of all windows including the ones on separate monitors.
If the saved desktop is reloaded but one or more of the monitors is not connected, the application should detect this. I have the following:
...
Windows windows = Window.GetWindow(pane);
if (window != null)
{
PaneTookWindow = toolWindow = window.Content as PaneToolWindow;
if (toolWindow != null)
{
if (!AreaInScreenBounds(new Rect(toolWindow.Left, toolWindow.Top, toolWindow.Width, toolWindow.Height)))
{
pane.ExecuteCommand(ContentPaneCommands.ChangeToDocument);
}
}
}
...
private static bool AreaInScreenBounds(Rect area)
{
if (Application.Current != null && Application.Current.MainWindow != null)
{
Rect [] screeAreas = Application.Current.MainWindow.GetScreenAreas();
return screenAreas.Any(screen => screen.Contains(area));
}
return false;
}
The problem is that this method does not detect whether the monitor is no longer available, but whether the area is outside of the MainWindow area.
Does anyone know, how to detect a disconnected monitor or a no longer available area?