Reputation: 4196
I create a fixed-size canvas in size of an A4 paper (21cm x 29,7cm).
I want this to scroll inside a ScrollViewer and a StackPanel. However, it seems that the ScrollViewer does not adapt its size to the window's size. How can I achieve this?
Here is my code so far. Text between curled brackets { } is removed for readability.
<Window {xmlns stuff here} Width="900" Height="1200" >
<StackPanel>
<my:Ribbon ShowQuickAccessToolBarOnTop="False">
{ ... Ribbon definition ... }
</my:Ribbon>
<ScrollViewer HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Visible" >
<Canvas x:Name="PageCanvas" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="21cm" Height="29.7cm" >
{ ... Various drawings and elements here ... }
</Canvas>
</ScrollViewer>
</StackPanel >
</Window>
Upvotes: 0
Views: 142
Reputation: 17850
The StackPanel is designed to grow indefinitely in one direction. So you can't accomplish your task without fixing the height of the StackPanel or without replacing StackPanel with another Panel (like Grid for example).
I suggest you use the Grid:
<Window {xmlns stuff here} Width="900" Height="1200" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto">
<RowDefinition Height="*">
</Grid.RowDefinitions>
<my:Ribbon ShowQuickAccessToolBarOnTop="False" Grid.Row="0">
{ ... Ribbon definition ... }
</my:Ribbon>
<ScrollViewer HorizontalScrollBarVisibility="Auto" Grid.Row="1"
VerticalScrollBarVisibility="Visible" >
<Canvas x:Name="PageCanvas" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="21cm" Height="29.7cm" >
{ ... Various drawings and elements here ... }
</Canvas>
</ScrollViewer>
</StackPanel >
</Window>
Upvotes: 1