MC9000
MC9000

Reputation: 2423

ScrollViewer does not scroll Image WPF

I have an image that is bigger than it's window container and it is placed in a ScrollViewer, however, the image does not scroll at all. I've tried putting the image in a container with no luck. What settings am I missing here? (I copied the code straight from MS, but they have it wrong)

Here's the code:

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:h="http://helixtoolkit.codeplex.com" x:Class="TileLayout"
Title="TileLayout" Height="1000" Width="845" WindowStartupLocation="CenterScreen" WindowStyle="ThreeDBorderWindow">
<StackPanel HorizontalAlignment="center" VerticalAlignment="Top">
    <StackPanel Orientation="Horizontal"   >
        <TextBox x:Name="txtSourceFilePath" Width="500" Margin="10" Height="22" TextChanged="TextBox_TextChanged" Text="E:\projects\Test3D\SavedSnapshots\snapshot.png"/>
        <Button x:Name="btnPickFile" Width="100" Margin="0,10,10,10" Content="Pick File" ></Button>
    </StackPanel>
    <ScrollViewer VerticalScrollBarVisibility="Auto" >
        <Image x:Name="imgFinal" Source="SteelMotion_chevron2.png"/>
    </ScrollViewer>
</StackPanel>

Upvotes: 0

Views: 2488

Answers (2)

Peilin Song
Peilin Song

Reputation: 24

You need to specify the size of the ScrollViewer. In this case ScrollViewer and Image are same size, so the scroll bar does not show.

Upvotes: 0

MC9000
MC9000

Reputation: 2423

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:h="http://helixtoolkit.codeplex.com" x:Class="TileLayout"
Title="TileLayout" Height="1000" Width="845" WindowStartupLocation="CenterScreen" WindowStyle="ThreeDBorderWindow">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="50"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <StackPanel Orientation="Horizontal" Height="50"  HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Row="0">
        <TextBox x:Name="txtSourceFilePath" Width="500" Margin="10" Height="22" TextChanged="TextBox_TextChanged" Text=""/>
        <Button x:Name="btnPickFile" Width="100" Margin="0,10,10,10" Content="Pick File" ></Button>
    </StackPanel>
    <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1" >
        <Image x:Name="imgFinal" Source="SteelMotion_chevron2.png" Width="768" Height="1408"/>
    </ScrollViewer>

</Grid>

Upvotes: 2

Related Questions