internal static DisplayRegionHelperInfo GetRegionInfo() { var instance = LifetimeHandler.GetDisplayRegionHelperInstance(); var info = new DisplayRegionHelperInfo(); info.Mode = TwoPaneViewMode.SinglePane; if (instance.m_simulateDisplayRegions) { // Create fake rectangles for test app if (instance.m_simulateMode == TwoPaneViewMode.Wide) { info.Regions[0] = m_simulateWide0; info.Regions[1] = m_simulateWide1; info.Mode = TwoPaneViewMode.Wide; } else if (instance.m_simulateMode == TwoPaneViewMode.Tall) { info.Regions[0] = m_simulateTall0; info.Regions[1] = m_simulateTall1; info.Mode = TwoPaneViewMode.Tall; } else { info.Regions[0] = m_simulateWide0; } } else { // ApplicationView.GetForCurrentView throws on failure; in that case we just won't do anything. ApplicationView view = null; try { view = ApplicationView.GetForCurrentView(); } catch { } if (view != null) { var rects = view.GetSpanningRects(); if (rects.Count == 2) { info.Regions = new Rect[rects.Count]; info.Regions[0] = new Rect(rects[0].Location.PhysicalToLogicalPixels(), rects[0].Size.PhysicalToLogicalPixels()); info.Regions[1] = new Rect(rects[1].Location.PhysicalToLogicalPixels(), rects[1].Size.PhysicalToLogicalPixels()); // Determine orientation. If neither of these are true, default to doing nothing. if (info.Regions[0].X < info.Regions[1].X && info.Regions[0].Y == info.Regions[1].Y) { // Double portrait info.Mode = TwoPaneViewMode.Wide; } else if (info.Regions[0].X == info.Regions[1].X && info.Regions[0].Y < info.Regions[1].Y) { // Double landscape info.Mode = TwoPaneViewMode.Tall; } } } } return(info); }