question

tre4b avatar image
0 Votes"
tre4b asked HuiLiu-MSFT commented

WPF Wrappanel Horizontal and vertical scrolling

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-wpf
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@tre4b. Could you show me the minimal code that reproduces the problem to analyze? And is it possible to show pictures to illustrate the actual and expected results?

0 Votes 0 ·
vb2ae avatar image
0 Votes"
vb2ae answered

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

tre4b avatar image
0 Votes"
tre4b answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.