Search code examples
wpfxamlvertical-scrolling

Xaml - Vertical scrollbar in stackpanel


I have creating a wpf application and in my settings panel I have tons of UI elements. The problem is that when I resize the window some of these elements are not visible anymore. Is there any way to add a simple vertical scrollbar?

I have tried this below and add my content into it :

    <ScrollViewer VerticalScrollBarVisibility="Auto">
       <Grid>
          <StackPanel>
              //Content
          </StackPanel>
       </Grid>
    </ScrollViewer>

I'm not sure if I put the ScrollViewer to the right Place but I got this error :

The member resources is not recognized or is not accessible

and for this error I have tried to replace the Page.Resources with Window.Resources but it did not help.

Anyways how could I get my vertical scrollbar working? Any helps?


Solution

  • Problem solved by removing the Width and Height properties from the Page.

    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Height="800" Width="1400"
          WindowTitle="ScrollViewer Sample">
      <ScrollViewer VerticalScrollBarVisibility="Auto">
         <Grid>
           <StackPanel>
              //Content
           </StackPanel>
         </Grid>
      </ScrollViewer>
    </Page>