private void VerifyViewMode(ViewMode mode) { // Verify configuration is correct for mode TwoPaneViewMode expectedConfiguration = TwoPaneViewMode.SinglePane; switch (mode) { case ViewMode.LeftRight: case ViewMode.RightLeft: expectedConfiguration = TwoPaneViewMode.Wide; break; case ViewMode.TopBottom: case ViewMode.BottomTop: expectedConfiguration = TwoPaneViewMode.Tall; break; } TextBlock configurationTextBlock = new TextBlock(FindElement.ByName("ConfigurationTextBlock")); Verify.AreEqual(expectedConfiguration.ToString(), configurationTextBlock.DocumentText); // Verify panes are actually being shown correctly ElementCache.Clear(); UIObject paneContent1 = TryFindElement.ByName("Content1"); UIObject paneContent2 = TryFindElement.ByName("Content2"); if (mode != ViewMode.Pane2Only) { Verify.IsNotNull(paneContent1, "Expected to find pane1"); Log.Comment("Content 1 dimensions: " + paneContent1.BoundingRectangle.ToString()); } if (mode != ViewMode.Pane1Only) { Verify.IsNotNull(paneContent2, "Expected to find pane2"); Log.Comment("Content 2 dimensions: " + paneContent2.BoundingRectangle.ToString()); } if (mode == ViewMode.Pane2Only) { Verify.IsNull(paneContent1, "Expected not to find pane1"); } if (mode == ViewMode.Pane1Only) { Verify.IsNull(paneContent2, "Expected not to find pane2"); } switch (mode) { case ViewMode.LeftRight: case ViewMode.RightLeft: Verify.AreEqual(paneContent1.BoundingRectangle.Top, paneContent2.BoundingRectangle.Top, "Verify panes are horizontally aligned"); if (mode == ViewMode.LeftRight) { Verify.IsGreaterThanOrEqual(paneContent2.BoundingRectangle.Left, paneContent1.BoundingRectangle.Right, "Verify left/right pane placement"); } else { Verify.IsGreaterThanOrEqual(paneContent1.BoundingRectangle.Left, paneContent2.BoundingRectangle.Right, "Verify right/left pane placement"); } break; case ViewMode.TopBottom: case ViewMode.BottomTop: Verify.AreEqual(paneContent1.BoundingRectangle.Left, paneContent2.BoundingRectangle.Left, "Verify panes are vertically aligned"); if (mode == ViewMode.TopBottom) { Verify.IsGreaterThanOrEqual(paneContent2.BoundingRectangle.Top, paneContent1.BoundingRectangle.Bottom, "Verify top/bottom pane placement"); } else { Verify.IsGreaterThanOrEqual(paneContent1.BoundingRectangle.Top, paneContent2.BoundingRectangle.Bottom, "Verify bottom/top pane placement"); } break; } }
/* static */ internal static void SimulateMode(TwoPaneViewMode value) { var instance = LifetimeHandler.GetDisplayRegionHelperInstance(); instance.m_simulateMode = value; }
private void AssertViewMode(ViewMode mode) { // Assert configuration is correct for mode TwoPaneViewMode expectedConfiguration = TwoPaneViewMode.SinglePane; switch (mode) { case ViewMode.LeftRight: case ViewMode.RightLeft: expectedConfiguration = TwoPaneViewMode.Wide; break; case ViewMode.TopBottom: case ViewMode.BottomTop: expectedConfiguration = TwoPaneViewMode.Tall; break; } Query configurationTextBlock = q => q.All().Marked("ConfigurationTextBlock"); Assert.AreEqual(expectedConfiguration.ToString(), new QueryEx(configurationTextBlock).GetText()); // Assert panes are actually being shown correctly QueryEx paneContent1Query = new QueryEx(q => q.All().Marked("TwoPaneView").Descendant().Marked("PART_Pane1ScrollViewer")); QueryEx paneContent2Query = new QueryEx(q => q.All().Marked("TwoPaneView").Descendant().Marked("PART_Pane2ScrollViewer")); var paneContent1 = _app.Query(paneContent1Query).FirstOrDefault(); var paneContent2 = _app.Query(paneContent2Query).FirstOrDefault(); var paneContent1BoundingRectangle = _app.Query(paneContent1Query).First().Rect; var paneContent2BoundingRectangle = _app.Query(paneContent2Query).First().Rect; var pane1Visibility = paneContent1Query.GetDependencyPropertyValue <string>("Visibility"); var pane2Visibility = paneContent2Query.GetDependencyPropertyValue <string>("Visibility"); if (mode != ViewMode.Pane2Only) { Assert.AreEqual("Visible", paneContent1Query.GetDependencyPropertyValue <string>("Visibility"), "Expected to find pane1"); Console.WriteLine("Content 1 dimensions: " + paneContent1BoundingRectangle.ToString()); } if (mode != ViewMode.Pane1Only) { Assert.AreEqual("Visible", paneContent2Query.GetDependencyPropertyValue <string>("Visibility"), "Expected to find pane2"); Console.WriteLine("Content 2 dimensions: " + paneContent2BoundingRectangle.ToString()); } if (mode == ViewMode.Pane2Only) { Assert.AreEqual("Collapsed", paneContent1Query.GetDependencyPropertyValue <string>("Visibility"), "Expected not to find pane1"); } if (mode == ViewMode.Pane1Only) { Assert.AreEqual("Collapsed", paneContent2Query.GetDependencyPropertyValue <string>("Visibility"), "Expected not to find pane2"); } switch (mode) { case ViewMode.LeftRight: case ViewMode.RightLeft: Assert.AreEqual(paneContent1BoundingRectangle.Y, paneContent2BoundingRectangle.Y, "Assert panes are horizontally aligned"); if (mode == ViewMode.LeftRight) { Assert.IsTrue(paneContent2BoundingRectangle.X >= paneContent1BoundingRectangle.Right, "Assert left/right pane placement"); } else { Assert.IsTrue(paneContent1BoundingRectangle.X >= -paneContent2BoundingRectangle.Right, "Assert right/left pane placement"); } break; case ViewMode.TopBottom: case ViewMode.BottomTop: Assert.AreEqual(paneContent1BoundingRectangle.X, paneContent2BoundingRectangle.X, "Assert panes are vertically aligned"); if (mode == ViewMode.TopBottom) { Assert.IsTrue(paneContent2BoundingRectangle.Y >= paneContent1BoundingRectangle.Bottom, "Assert top/bottom pane placement"); } else { Assert.IsTrue(paneContent1BoundingRectangle.Y >= paneContent2BoundingRectangle.Bottom, "Assert bottom/top pane placement"); } break; } }
void UpdateMode() { // Don't bother running this logic until after we hit OnApplyTemplate. if (!m_loaded) { return; } double controlWidth = ActualWidth; double controlHeight = ActualHeight; ViewMode newMode = (PanePriority == TwoPaneViewPriority.Pane1) ? ViewMode.Pane1Only : ViewMode.Pane2Only; // Calculate new mode DisplayRegionHelperInfo info = DisplayRegionHelper.GetRegionInfo(); Rect rcControl = GetControlRect(); bool isInMultipleRegions = IsInMultipleRegions(info, rcControl); if (isInMultipleRegions) { if (info.Mode == TwoPaneViewMode.Wide) { // Regions are laid out horizontally if (WideModeConfiguration != TwoPaneViewWideModeConfiguration.SinglePane) { newMode = (WideModeConfiguration == TwoPaneViewWideModeConfiguration.LeftRight) ? ViewMode.LeftRight : ViewMode.RightLeft; } } else if (info.Mode == TwoPaneViewMode.Tall) { // Regions are laid out vertically if (TallModeConfiguration != TwoPaneViewTallModeConfiguration.SinglePane) { newMode = (TallModeConfiguration == TwoPaneViewTallModeConfiguration.TopBottom) ? ViewMode.TopBottom : ViewMode.BottomTop; } } } else { // One region if (controlWidth > MinWideModeWidth && WideModeConfiguration != TwoPaneViewWideModeConfiguration.SinglePane) { // Split horizontally newMode = (WideModeConfiguration == TwoPaneViewWideModeConfiguration.LeftRight) ? ViewMode.LeftRight : ViewMode.RightLeft; } else if (controlHeight > MinTallModeHeight && TallModeConfiguration != TwoPaneViewTallModeConfiguration.SinglePane) { // Split vertically newMode = (TallModeConfiguration == TwoPaneViewTallModeConfiguration.TopBottom) ? ViewMode.TopBottom : ViewMode.BottomTop; } } // Update row/column sizes (this may need to happen even if the mode doesn't change) UpdateRowsColumns(newMode, info, rcControl); // Update mode if necessary if (newMode != m_currentMode) { m_currentMode = newMode; TwoPaneViewMode newViewMode = TwoPaneViewMode.SinglePane; switch (m_currentMode) { case ViewMode.Pane1Only: VisualStateManager.GoToState(this, "ViewMode_OneOnly", true); break; case ViewMode.Pane2Only: VisualStateManager.GoToState(this, "ViewMode_TwoOnly", true); break; case ViewMode.LeftRight: VisualStateManager.GoToState(this, "ViewMode_LeftRight", true); newViewMode = TwoPaneViewMode.Wide; break; case ViewMode.RightLeft: VisualStateManager.GoToState(this, "ViewMode_RightLeft", true); newViewMode = TwoPaneViewMode.Wide; break; case ViewMode.TopBottom: VisualStateManager.GoToState(this, "ViewMode_TopBottom", true); newViewMode = TwoPaneViewMode.Tall; break; case ViewMode.BottomTop: VisualStateManager.GoToState(this, "ViewMode_BottomTop", true); newViewMode = TwoPaneViewMode.Tall; break; } if (newViewMode != Mode) { SetValue(ModeProperty, newViewMode); ModeChanged?.Invoke(this, this); } } }
public DisplayRegionHelperInfo(TwoPaneViewMode mode = TwoPaneViewMode.SinglePane) { Regions = new Rect[c_maxRegions]; Mode = mode; }