Issues with Measure/Arrange in custom Control With FlipView RRS feed

  • Question

  • Hi all,

    I'm having some issues with Measure/Arrange in my custom control. My control uses a FlipView, which in turns contains some ScrollViewers, that in turn contain content.

    I want the control to take up as much space as is available at any time.

    I tried to override MeasureOverride and ArrangeOverride, but can't seem to get it right. The elements inside the FlipView always end up with a size of 0.

    I created a small simplified sample problem to work on the core of the problem. It looks as following:

        class CustomControl : ContentControl
            private List<Canvas> _ChildCanvases;
            private FlipView _ChildFlipView;
            private List<ScrollViewer> _ChildScrollViewers;
            public CustomControl()
                this.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch;
                this.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch;
                _ChildFlipView = new FlipView();
                _ChildFlipView.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Stretch;
                _ChildFlipView.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Stretch;
                _ChildFlipView.Background = new SolidColorBrush(Colors.Olive);
                this.Content = _ChildFlipView;
                _ChildScrollViewers = new List<ScrollViewer>();
                _ChildCanvases = new List<Canvas>();
                for (int i = 0; i < 3; i++)
                    ScrollViewer sv = new ScrollViewer();
                    Canvas c = new Canvas();
                    c.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red);
                    c.Width = 4000;
                    c.Height = 8000;
                    sv.Content = c;
                    //sv.Width = 1000;
                    //sv.Height = 1000;
            protected override Windows.Foundation.Size MeasureOverride(Size availableSize)
                Size size = new Size(availableSize.Width, availableSize.Height);
                _ChildFlipView.Measure(new Size(availableSize.Width, availableSize.Height));
                return size;
            protected override Windows.Foundation.Size ArrangeOverride(Size finalSize)
                _ChildFlipView.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height));
                return new Size(finalSize.Width, finalSize.Height);

    I want to stick this control inside, say a Grid. The problem is, that once the control is laid out, the ScrollViewer's are all of width and height 0.

    Any idea why this might be?



    Thursday, August 14, 2014 7:15 PM