Mihir Patel
Mihir Patel

Reputation: 486

Left and Right Scrolling in Image

i want to display large image in small control such that entire image can be scrolled. for this, i have used following code but i could only succeed in achieving vertical scrolling. what should i do for enabling both, horizontal and vertical scrolling ?

        <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Width="470">
        <ScrollViewer x:Name="scrollViewer" Width="470" Height="270" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Image Name="drag" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Top"/>
        </ScrollViewer>
    </Grid>

if there is any other solution than using scrollviewer then please share it, or mention any changes in this code which are useful for achieving the same.

Upvotes: 0

Views: 63

Answers (1)

Null Pointer
Null Pointer

Reputation: 9309

Try

<Grid HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Width="470">
    <ScrollViewer x:Name="scrollViewer" Width="470" Height="270" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"HorizontalAlignment="Left" VerticalAlignment="Top">
        <Image Name="drag" Stretch="None" HorizontalAlignment="Center" VerticalAlignment="Top"/>
    </ScrollViewer>
</Grid>

You need to set HorizontalScrollBarVisibility and VerticalScrollBarVisibility properties to achieve desired scrolling.

Edit :

If you want to see the scroll bars always you can set HorizontalScrollBarVisibility="Visible" and VerticalScrollBarVisibility="Visible" .Otherwise("Auto") scroll bars will appear based on the content size

Upvotes: 2

Related Questions