public void Next_Continue_Returns_Next_Control_In_Container() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { Children = new Controls { new Button { Name = "Button1" }, (current = new Button { Name = "Button2" }), (next = new Button { Name = "Button3" }), } }), new StackPanel { Children = new Controls { new Button { Name = "Button4" }, new Button { Name = "Button5" }, new Button { Name = "Button6" }, } }, } }; var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next); Assert.Equal(next, result); }
private Control GetHeader(VisualTreeNode node) { var result = new StackPanel { Orientation = Orientation.Horizontal, Gap = 8, Children = new Controls { new TextBlock { FontStyle = node.IsInTemplate ? FontStyle.Italic : FontStyle.Normal, Text = node.Type, }, new TextBlock { [!TextBlock.TextProperty] = node.WhenAnyValue(x => x.Classes), } } }; result.PointerEnter += this.AddAdorner; result.PointerLeave += this.RemoveAdorner; return result; }
public void Invalidating_Child_Should_Remeasure_Parent() { var layoutManager = new LayoutManager(); using (PerspexLocator.EnterScope()) { PerspexLocator.CurrentMutable.Bind<ILayoutManager>().ToConstant(layoutManager); Border border; StackPanel panel; var root = new TestLayoutRoot { Child = panel = new StackPanel { Children = new Controls.Controls { (border = new Border()) } } }; layoutManager.ExecuteInitialLayoutPass(root); Assert.Equal(new Size(0, 0), root.DesiredSize); border.Width = 100; border.Height = 100; layoutManager.ExecuteLayoutPass(); Assert.Equal(new Size(100, 100), panel.DesiredSize); } }
public void GetNextInTabOrder_Continue_Returns_First_Control_In_Next_Sibling_Container() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { Children = new Controls { new Button { Name = "Button1" }, new Button { Name = "Button2" }, (current = new Button { Name = "Button3" }), } }), new StackPanel { Children = new Controls { (next = new Button { Name = "Button4" }), new Button { Name = "Button5" }, new Button { Name = "Button6" }, } }, } }; var result = KeyboardNavigationHandler.GetNextInTabOrder(current); Assert.Equal(next, result); }
public void Track_By_Name_Should_Find_Control_Added_Later() { StackPanel panel; TextBlock relativeTo; var root = new TestRoot { Child = (panel = new StackPanel { Children = new Controls.Controls { (relativeTo = new TextBlock { Name = "start" }), } }) }; var locator = ControlLocator.Track(relativeTo, "target"); var target = new TextBlock { Name = "target" }; var result = new List<IControl>(); using (locator.Subscribe(x => result.Add(x))) { panel.Children.Add(target); } Assert.Equal(new[] { null, target }, result); Assert.Equal(0, root.NameScopeRegisteredSubscribers); Assert.Equal(0, root.NameScopeUnregisteredSubscribers); }
public void Should_Bind_To_Later_Added_Element() { TextBlock target; StackPanel stackPanel; var root = new TestRoot { Child = stackPanel = new StackPanel { Children = new Controls.Controls { (target = new TextBlock { Name = "target", }), } } }; var binding = new Binding { ElementName = "source", Path = "Text", }; binding.Bind(target, TextBlock.TextProperty); stackPanel.Children.Add(new TextBlock { Name = "source", Text = "foo", }); Assert.Equal("foo", target.Text); }
public void GetNextInTabOrder_Continue_Returns_Child_Of_Top_Level() { Button next; var top = new StackPanel { Children = new Controls { (next = new Button { Name = "Button1" }), } }; var result = KeyboardNavigationHandler.GetNextInTabOrder(top); Assert.Equal(next, result); }
public void Invalidating_Child_Should_Not_Invalidate_Parent() { var panel = new StackPanel(); var child = new Border(); panel.Children.Add(child); panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Assert.Equal(new Size(0, 0), panel.DesiredSize); child.Width = 100; child.Height = 100; Assert.True(panel.IsMeasureValid); Assert.False(child.IsMeasureValid); panel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Assert.Equal(new Size(0, 0), panel.DesiredSize); }
public void Lays_Out_Children_Vertically() { var target = new StackPanel { Children = new Controls { new Border { Height = 20, Width = 120 }, new Border { Height = 30 }, new Border { Height = 50 }, } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(120, 100), target.Bounds.Size); Assert.Equal(new Rect(0, 0, 120, 20), target.Children[0].Bounds); Assert.Equal(new Rect(0, 20, 120, 30), target.Children[1].Bounds); Assert.Equal(new Rect(0, 50, 120, 50), target.Children[2].Bounds); }
public void Lays_Out_Children_Horizontally() { var target = new StackPanel { Orientation = Orientation.Horizontal, Children = new Controls { new Border { Width = 20, Height = 120 }, new Border { Width = 30 }, new Border { Width = 50 }, } }; target.Measure(Size.Infinity); target.Arrange(new Rect(target.DesiredSize)); Assert.Equal(new Size(100, 120), target.Bounds.Size); Assert.Equal(new Rect(0, 0, 20, 120), target.Children[0].Bounds); Assert.Equal(new Rect(20, 0, 30, 120), target.Children[1].Bounds); Assert.Equal(new Rect(50, 0, 50, 120), target.Children[2].Bounds); }
public void Down_Contained_Stops_At_End() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Contained, Children = new Controls { (next = new Button { Name = "Button1" }), new Button { Name = "Button2" }, (current = new Button { Name = "Button3" }), } }), new StackPanel { [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Contained, Children = new Controls { new Button { Name = "Button4" }, new Button { Name = "Button5" }, new Button { Name = "Button6" }, } }, } }; var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Down); Assert.Null(result); }
public void Down_Continue_Returns_First_Control_In_Down_Sibling_Container() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue, Children = new Controls { new Button { Name = "Button1" }, new Button { Name = "Button2" }, (current = new Button { Name = "Button3" }), } }), new StackPanel { [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue, Children = new Controls { (next = new Button { Name = "Button4" }), new Button { Name = "Button5" }, new Button { Name = "Button6" }, } }, } }; var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Down); Assert.Equal(next, result); }
public void Up_Cycle_Wraps_To_Last() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Cycle, Children = new Controls { (current = new Button { Name = "Button1" }), new Button { Name = "Button2" }, (next = new Button { Name = "Button3" }), } }), new StackPanel { [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Cycle, Children = new Controls { new Button { Name = "Button4" }, new Button { Name = "Button5" }, new Button { Name = "Button6" }, } }, } }; var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Up); Assert.Equal(next, result); }
public void Up_Contained_Doesnt_Return_Child_Control() { Decorator current; var top = new StackPanel { [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Contained, Children = new Controls { (current = new Decorator { Focusable = true, Child = new Button(), }) } }; var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Up); Assert.Null(result); }
public void GetPreviousInTabOrder_Once_Moves_To_Previous_Container() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { Children = new Controls { new Button { Name = "Button1" }, new Button { Name = "Button2" }, (next = new Button { Name = "Button3" }), } }), new StackPanel { [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once, Children = new Controls { new Button { Name = "Button4" }, (current = new Button { Name = "Button5" }), new Button { Name = "Button6" }, } }, } }; var result = KeyboardNavigationHandler.GetPreviousInTabOrder(current); Assert.Equal(next, result); }
public void GetPreviousInTabOrder_Continue_Wraps() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { new StackPanel { Children = new Controls { (container = new StackPanel { Children = new Controls { (current = new Button { Name = "Button1" }), new Button { Name = "Button2" }, new Button { Name = "Button3" }, } }), }, }, new StackPanel { Children = new Controls { new Button { Name = "Button4" }, new Button { Name = "Button5" }, (next = new Button { Name = "Button6" }), } }, } }; var result = KeyboardNavigationHandler.GetPreviousInTabOrder(current); Assert.Equal(next, result); }
private Control GetHeader(LogicalTreeNode node) { var result = new StackPanel { Orientation = Orientation.Horizontal, Gap = 8, Children = new Controls { new TextBlock { Text = node.Type, }, new TextBlock { [!TextBlock.TextProperty] = node.WhenAnyValue(x => x.Classes), } } }; result.PointerEnter += AddAdorner; result.PointerLeave += RemoveAdorner; return result; }
public void GetNextInTabOrder_Cycle_Wraps_To_First() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle, Children = new Controls { (next = new Button { Name = "Button1" }), new Button { Name = "Button2" }, (current = new Button { Name = "Button3" }), } }), new StackPanel { Children = new Controls { new Button { Name = "Button4" }, new Button { Name = "Button5" }, new Button { Name = "Button6" }, } }, } }; var result = KeyboardNavigationHandler.GetNextInTabOrder(current); Assert.Equal(next, result); }
public void Previous_Once_Moves_To_Active_Element() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once, Children = new Controls { new Button { Name = "Button1" }, (next = new Button { Name = "Button2" }), new Button { Name = "Button3" }, } }), new StackPanel { Children = new Controls { (current = new Button { Name = "Button4" }), new Button { Name = "Button5" }, new Button { Name = "Button6" }, } }, } }; KeyboardNavigation.SetTabOnceActiveElement(container, next); var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous); Assert.Equal(next, result); }
public void Track_By_Name_Should_Track_Removal_And_Readd() { StackPanel panel; TextBlock target; TextBlock relativeTo; var root = new TestRoot { Child = panel = new StackPanel { Children = new Controls.Controls { (target = new TextBlock { Name = "target" }), (relativeTo = new TextBlock { Name = "start" }), } } }; var locator = ControlLocator.Track(relativeTo, "target"); var result = new List<IControl>(); locator.Subscribe(x => result.Add(x)); var other = new TextBlock { Name = "target" }; panel.Children.Remove(target); panel.Children.Add(other); Assert.Equal(new[] { target, null, other }, result); }
public void Previous_Contained_Returns_Previous_Control_In_Container() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained, Children = new Controls { (next = new Button { Name = "Button1" }), (current = new Button { Name = "Button2" }), new Button { Name = "Button3" }, } }), new StackPanel { Children = new Controls { new Button { Name = "Button4" }, new Button { Name = "Button5" }, new Button { Name = "Button6" }, } }, } }; var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous); Assert.Equal(next, result); }
public void Previous_Continue_Returns_Last_Child_Of_Sibling() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { Children = new Controls { new Button { Name = "Button1" }, new Button { Name = "Button2" }, (next = new Button { Name = "Button3" }), } }), (current = new Button { Name = "Button4" }), } }; var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Previous); Assert.Equal(next, result); }
public void Should_Bind_To_Later_Added_Element() { ContentControl target; StackPanel stackPanel; var root = new TestRoot { Child = stackPanel = new StackPanel { Children = new Controls.Controls { (target = new ContentControl { Name = "target", }), } } }; var binding = new Binding { ElementName = "source", }; binding.Bind(target, ContentControl.ContentProperty); var source = new TextBlock { Name = "source", Text = "foo", }; stackPanel.Children.Add(source); Assert.Same(source, target.Content); }
public void Down_Continue_Returns_Child_Of_Top_Level() { Button next; var top = new StackPanel { [KeyboardNavigation.DirectionalNavigationProperty] = KeyboardNavigationMode.Continue, Children = new Controls { (next = new Button { Name = "Button1" }), } }; var result = KeyboardNavigationHandler.GetNext(top, FocusNavigationDirection.Down); Assert.Equal(next, result); }
public void Next_Continue_Doesnt_Enter_Panel_With_TabNavigation_None() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { Children = new Controls { (next = new Button { Name = "Button1" }), new Button { Name = "Button2" }, (current = new Button { Name = "Button3" }), } }), new StackPanel { [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.None, Children = new Controls { new StackPanel { Children = new Controls { new Button { Name = "Button4" }, new Button { Name = "Button5" }, new Button { Name = "Button6" }, } }, } } } }; var result = KeyboardNavigationHandler.GetNext(current, FocusNavigationDirection.Next); Assert.Equal(next, result); }
public void GetNextInTabOrder_Never_Skips_Container() { StackPanel container; Button current; Button next; var top = new StackPanel { Children = new Controls { (container = new StackPanel { [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Never, Children = new Controls { new Button { Name = "Button1" }, new Button { Name = "Button2" }, new Button { Name = "Button3" }, } }), new StackPanel { Children = new Controls { (next = new Button { Name = "Button4" }), new Button { Name = "Button5" }, (current = new Button { Name = "Button6" }), } }, } }; KeyboardNavigation.SetTabOnceActiveElement(container, next); var result = KeyboardNavigationHandler.GetNextInTabOrder(current); Assert.Equal(next, result); }