Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Scrollbars to Grid

How does one add scrollbars to a grid?

    <Grid>
        <Menu Height="23" Name="menu1" VerticalAlignment="Top">
            <MenuItem Header="File">
                <MenuItem Command="ApplicationCommands.New" Header="New" />
                <MenuItem Command="ApplicationCommands.Save" Header="Save" />
                <MenuItem Command="ApplicationCommands.Open" Header="Open" />
                <MenuItem Command="ApplicationCommands.Close" Header="Exit" />
            </MenuItem>
            <MenuItem Header="Stuff">
                <MenuItem Header="Properties" Command="Properties"/>
                <MenuItem Header="Tileset" Command="Replace"/>
            </MenuItem>
        </Menu>
        <Grid Margin="0,24,0,0">
            <Canvas HorizontalAlignment="Stretch" Name="canvas1" VerticalAlignment="Stretch" MouseMove="MoveMouse" MouseDown="PressDownMouse" MouseUp="canvas2_MouseLeftButtonUp" MouseWheel="canvas1_MouseWheel"/>
            <Canvas HorizontalAlignment="Stretch" Name="canvas2" VerticalAlignment="Stretch" MouseMove="MoveMouse" MouseDown="PressDownMouse" MouseUp="canvas2_MouseLeftButtonUp" MouseWheel="canvas1_MouseWheel"/>
            <ListView HorizontalAlignment="Left" Name="listView1" Width="203" VerticalAlignment="Stretch" SelectionChanged="listView1_SelectionChanged">
            </ListView>
        </Grid>
    </Grid>

Two canvases may be too high or too wide.

This is Tile Map Editor and I draw everything on canvas. In the ListView I have tiles to insert.

like image 326
Greggy Avatar asked Mar 30 '15 19:03

Greggy


People also ask

How do I add a ScrollBar?

Suppose we want to add a scroll bar option in HTML, use an “overflow” option and set it as auto-enabled for adding both horizontal and vertical scroll bars. If we want to add a vertical bar option in Html, add the line “overflow-y” in the files.

How do I get my scroll bar to show?

Show scroll bars in Word and Excel for WindowsClick File > Options. On the Advanced tab, scroll to the Display section. Select Show horizontal scroll bar and Show vertical scroll bar, and then click OK.

Why is my scroll bar not showing?

If the vertical scroll bar disappears completely in Word, check File / Options / Advanced. Make sure the box is checked to Show vertical scroll bar. If you want to work around the disappearing Word scroll bar, click on View / Draft.


1 Answers

Usually you can wrap the element with <ScrollViewer> or set ScrollViewer.HorizontalScrollBarVisibility and ScrollViewer.VerticalScrollBarVisibility inside the element's XAML. I like setting to Auto, so that they show up only when needed.

Just try this to start:

<ScrollViewer>
  <Grid>
  // some code
  </Grid>
</ScrollViewer>

EDIT for further help! Here's an example of a better layout, the listview is on the left followed by the two canvases. You may want to put these above each other or have a different layout, but this will show you how to do it:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Menu Name="menu1" >
        <MenuItem Header="File">
            <MenuItem Command="ApplicationCommands.New" Header="New" />
            <MenuItem Command="ApplicationCommands.Save" Header="Save" />
            <MenuItem Command="ApplicationCommands.Open" Header="Open" />
            <MenuItem Command="ApplicationCommands.Close" Header="Exit" />
        </MenuItem>
        <MenuItem Header="Stuff">
            <MenuItem Header="Properties" Command="Properties"/>
            <MenuItem Header="Tileset" Command="Replace"/>
        </MenuItem>
    </Menu>
    <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <ListView />
        <Canvas Grid.Column="1"/>
        <Canvas Grid.Column="2"/>
    </Grid>
</Grid>
like image 54
Theodosius Von Richthofen Avatar answered Oct 06 '22 19:10

Theodosius Von Richthofen