WPF Wrappanel Horizontal and vertical scrolling

Tre4b 136 Reputation points
2022-05-20T20:35:08.203+00:00

The way my app is setup I want to be able to have two views of the controls on my page.

I want to be able to scroll up and down through several lines of controls the width of the app window. I also want to horizontally scroll through the controls left to right at one control high. I use a slider to set the height of the controls and to be able to vary this.

I decided to use a Wrappanel for this. I put it in a ScrollViewer and easily created the Vertical scrolling viewer.

Then I added a checkbox for changing to HorizontalScrolling and implemented these handlers

        private void Horizontal_Checked(object sender, RoutedEventArgs e)
        {
            SB.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
            SB.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
        }

        private void Horizontal_Unchecked(object sender, RoutedEventArgs e)
        {
            SB.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;
            SB.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
            SB.InvalidateMeasure();
        }

The app then ran scrolled fine vertically. When I click Horizontal it changes to a horizontal scroll one control high. Perfect.

The challenge is that when you untick it remains horizontally scrolling. I've tried invalidating anything that can be on both the SB (which should really have been SV at the least!) and on the WrapPanel and even the Grid they are both in. No dice. I even tried clearing the Children of the WrapPanel but it remainded with all of them in resolutely scrolling horizontally. If I vary the slider for height then the size of the controls still change.

I need the panel to recalculate the layout and then refresh but cannot figure out how. Any ideas?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,670 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2022-05-22T11:07:03.637+00:00

    Wouldn't you want to change the wrappanels orientation to Horizontal if you want horizontal scrolling?

    0 comments No comments

  2. Tre4b 136 Reputation points
    2022-05-22T11:12:14.303+00:00

    I thought so, however I cannot seem to access the orientation element of the wrap panel when it is running so I assumed this was runtime only.

    0 comments No comments