Enclosing everything in a ScrollViewer (in xbap application)

Respondida Enclosing everything in a ScrollViewer (in xbap application)

  • Thursday, August 30, 2012 6:50 PM
     
      Has Code

    I have an xbap application, and I need scroll bars to appear in the browser window when the window is resized to be smaller than the Grid that serves as its parent element. Following the advice here and here, I tried to put everything in a ScrollViewer, but that doesn't fix the problem.

    I'm going from this:

    <Page Height="x" Width="y">
       <Grid Height="less-than-x" Width="less-than-y">
         <!-- Page content -->
       </Grid>
    </Page>

    to this:

    <Page Height="x" Width="y">
       <ScrollViewer HorizontalScrollBarVisibility="Visible">
          <Grid Height="less-than-x" Width="less-than-y">
             <!-- Page content -->
          </Grid>
       </ScrollViewer>
    </Page>

    but it doesn't work - within very small ranges the scroll bars move with the application, but shrinking the browser window beyond a certain size makes the scroll bars disappear. I need the scroll bars to appear regardless of browser window size - it's OK if they're not on the edge of the browser window when the window is larger than the application content, but they must be on the edge when its smaller.

    I tried giving the Grid MinHeight and MinWidth attributes instead - no luck.

    Just FYI, the Grid contains a lot of absolutely and relatively positioned elements that I don't want to change unless I really have to - this is an application I'm inheriting from someone else.



    • Edited by Alex Slover Thursday, August 30, 2012 6:52 PM
    •  

All Replies

  • Thursday, August 30, 2012 9:29 PM
     
     Answered Has Code

    I seem to have fixed the problem. If anyone else runs across this issue, the solution is to set the Page element to Auto size root, enable automatic sizing on the ScrollViewer, and enforce a minimum size on the Grid, so the code looks like:

    <Page d:DesignHeight="y" d:DesignWidth="x">
      <ScrollViewer Height="Auto" Width="Auto" HorizontalScrollBarVisibility="Visible">
         <Grid MinHeight="x" MinWidth="y">
            <!-- Content -->
         </Grid>
       </ScrollViewer>
    </Page>

    • Marked As Answer by Alex Slover Thursday, August 30, 2012 9:29 PM
    •  
  • Friday, August 31, 2012 6:44 AM
    Moderator
     
     

    Hi Alex Slover,

    Thank you for sharing your solution here.

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.