-1

So just creating a basic app, complete noob, how do i scroll

<Grid>
   <Textblock>
   <Button>
   <Textblock>
   <Button>
   <Textblock>
   <Button>
   <Textblock>
   <Button>
    ......
</Grid>

just a basic grid with many textblock and buttons , now as it doesnt fit on the screen , how do i make a scrollbar appear to scroll downwards.

Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
Pratish Shrestha
  • 1,712
  • 4
  • 17
  • 26
  • 2
    No offense, but I just googled "How to put a scrollbar in XAML" and found a lot of answers, including [this](http://stackoverflow.com/questions/6068860/how-to-add-a-scrollbar-to-window-in-c-sharp). – The One Oct 03 '14 at 17:16
  • possible duplicate of [Enabling Scrollbar in WPF](http://stackoverflow.com/questions/736153/enabling-scrollbar-in-wpf) – The One Oct 03 '14 at 17:28
  • error occurs " content can only be set once" – Pratish Shrestha Oct 03 '14 at 17:31

1 Answers1

2

You'll need a ScrollViewer control, and (since the ScrollViewer allows only one content element) some layout container as, for example, a StackPanel. Example:

<Grid>
    <ScrollViewer>
        <StackPanel Orientation="Vertical">
            <Textblock>
            <Button>
            <Textblock>
            <Button>
            <Textblock>
            <Button>
            <Textblock>
            <Button>
            ......
        </StackPanel>
    </ScrollViewer>
</Grid>
andreask
  • 4,248
  • 1
  • 20
  • 25
  • This is correct, but don't use a stackpanel, use a `DockPanel`. `DockPanel` will adapt the correct height, whereas `StackPanel` will just keep going and never get a scrollbar unless you specify a `Height` for it. – DLeh Oct 03 '14 at 17:20
  • thanks, it is now scrollable but the layout changed completely, the textblocks and buttons are like only two of them in one screen. – Pratish Shrestha Oct 03 '14 at 17:22
  • @DLeh how do i use the dockpanel – Pratish Shrestha Oct 03 '14 at 17:26
  • Error 1 DockPanel is not supported in a Windows App project. – Pratish Shrestha Oct 03 '14 at 17:35
  • Sorry, I guess `DockPanel`s are in WPF. Maybe you don't need it with the way `StackPanel`s are done in Windows Apps. Use google, there will be plenty of other answers about how to make a scroll bar. – DLeh Oct 03 '14 at 17:45