1

I want to add scroll view to my program and I tried ScrollView control but that don't take effect. It's my first time dealing with scrolls please help me :).

My xaml Code:

<DockPanel Grid.Row="1" Background="#FF695887"> <ScrollViewer VerticalScrollBarVisibility="Auto" Height="795"> <Canvas Name="zemelapis" Height="Auto" Width="Auto"> <Image Name="pav_kelias" /> <Image Name="car1" /> </Canvas> </ScrollViewer> </DockPanel> 

Because these 2 images is not fitting here I need a scroll for them. Maybe I should use ScrollBar?

My program example: https://gyazo.com/a4ba7e4d5004632e2229a87e686c4c09 , as you can see bottom image is not fitting in range of window.

1
  • 1
    What if you change the Canvas to a Grid, or some other type of control or setting a defined height on the Canvas? Commented Mar 16, 2016 at 14:29

2 Answers 2

4

You have specified Auto as Height and Width. This implies that the Canvas will fill the height available to it.

From the documentation:

Auto sizing behavior implies that the element will fill the height available to it.

In this case the available height is the height of the ScrollViewer.

If you want the Canvas to be bigger, and hence the ScrollViewer to scroll, you should set a height on Canvas that is bigger than the height of ScrollViewer.

So, for example:

<DockPanel Grid.Row="1" Background="#FF695887"> <ScrollViewer VerticalScrollBarVisibility="Auto" Height="795"> <Canvas Name="zemelapis" Height="1000" Width="Auto"> <Image Name="pav_kelias" /> <Image Name="car1" /> </Canvas> </ScrollViewer> </DockPanel> 
Sign up to request clarification or add additional context in comments.

Comments

3

If you want your ScrollViewer to work easily, use a Grid instead of a Canvas:

<DockPanel Background="#FF695887"> <ScrollViewer > <Grid Name="zemelapis"> <Image Name="pav_kelias" Source="acteurs.png"/> <Image Name="car1" Source="public.jpg"/> </Grid> </ScrollViewer> </DockPanel> 

As explain by Domysee, Canvas gives you total control of the layout. Grid however will automatically adjust its size depending on the content.

See http://www.wpf-tutorial.com/panels/introduction-to-wpf-panels/

1 Comment

not working that way I want. I need Canvas anyway cause I manipulate with coordinates like GetTop, GetLeft...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.