private void InitializeComponent() { Func<object, IEnumerable<Control>> pt = PropertyTemplate; Content = new ScrollViewer { Content = new SimpleGrid { Styles = new Styles { new Style(x => x.Is<Control>()) { Setters = new[] { new Setter(MarginProperty, new Thickness(2)), } }, }, [GridRepeater.TemplateProperty] = pt, [!GridRepeater.ItemsProperty] = this.WhenAnyValue(x => x.ViewModel.Properties).ToBinding(), } }; }
public void Test_ScrollViewer_With_TextBlock() { using (var context = AvaloniaLocator.EnterScope()) { RegisterServices(); ScrollViewer scrollViewer; TextBlock textBlock; var window = new Window() { Width = 800, Height = 600, SizeToContent = SizeToContent.WidthAndHeight, Content = scrollViewer = new ScrollViewer { Width = 200, Height = 200, CanScrollHorizontally = true, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Content = textBlock = new TextBlock { Width = 400, Height = 400, Text = "Hello World!", }, } }; LayoutManager.Instance.ExecuteInitialLayoutPass(window); Assert.Equal(new Size(800, 600), window.Bounds.Size); Assert.Equal(new Size(200, 200), scrollViewer.Bounds.Size); Assert.Equal(new Point(300, 200), Position(scrollViewer)); Assert.Equal(new Size(400, 400), textBlock.Bounds.Size); var scrollBars = scrollViewer.GetTemplateChildren().OfType<ScrollBar>().ToList(); var presenters = scrollViewer.GetTemplateChildren().OfType<ScrollContentPresenter>().ToList(); Assert.Equal(2, scrollBars.Count); Assert.Equal(1, presenters.Count); var presenter = presenters[0]; Assert.Equal(new Size(190, 190), presenter.Bounds.Size); var horzScroll = scrollBars.Single(x => x.Orientation == Orientation.Horizontal); var vertScroll = scrollBars.Single(x => x.Orientation == Orientation.Vertical); Assert.True(horzScroll.IsVisible); Assert.True(vertScroll.IsVisible); Assert.Equal(new Size(190, 10), horzScroll.Bounds.Size); Assert.Equal(new Size(10, 190), vertScroll.Bounds.Size); Assert.Equal(new Point(0, 190), Position(horzScroll)); Assert.Equal(new Point(190, 0), Position(vertScroll)); } }