0

I am using a ScrollViewer which is inside a Grid control and its alignment is center to screen . There is a web browser control inside the Scrolllviewer and the height and width vary based on size of web page. If height is too big scrollviewer scroller will appear Rough xaml is like this

<Grid>
 <ScrollViewer HAlign="Center" RAlign="Center">
   <Browser/>
 </ScrollViewer/>
</Grid>

Now i need a button with position always left to scrollviewer and another button which always be right to scrollviewer and vertically center to the screen

if i place button inside scrollviewer what will happen is if the height of browser is too long , button will also goes down . A sample layout can be look like it enter image description here

1
  • did you try using dockpanel?
    – pushpraj
    Commented Sep 12, 2014 at 6:10

1 Answer 1

2

here is how I would use a DockPanel for the same

<Grid>
    <DockPanel LastChildFill="True" HorizontalAlignment="Center" VerticalAlignment="Center" MaxWidth="500">
        <Button Content="Prev page" DockPanel.Dock="Left"/>
        <Button Content="Next page" DockPanel.Dock="Right"/>
        <ScrollViewer>
            <WebBrowser Source="http://www.google.com"/>
        </ScrollViewer>
    </DockPanel>
</Grid>

result

result

above is just an example to show the use of DockPanel


Using Grid

you can use grid with column definitions to enable the stretch to available space or * width

example

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*" />
        <ColumnDefinition Width="4*"
                          MaxWidth="500" />
        <ColumnDefinition Width="1*" />
    </Grid.ColumnDefinitions>
    <Button Content="Prev page"
            DockPanel.Dock="Left" />
    <ScrollViewer Grid.Column="1">
        <WebBrowser Source="http://www.google.com" />
    </ScrollViewer>
    <Button Content="Next page"
            DockPanel.Dock="Right"
            Grid.Column="2" />
</Grid>

above example divides grid into 3 columns with 1:4:1 proportion of width. so this will enable to distribute the available space using the defined proportion. additionally I have set the max width to the browser column as 500 px, this will enable the stretching of buttons after the defined width has reached.

1
  • How can i make sure the buttons on Left and Right consume all the available space to left and right of browser control . Here in above example MaxWidth is set as 500 px. But in case if its value is not set then how can i make the button as stretch
    – Sebastian
    Commented Sep 15, 2014 at 5:02

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.