I'm having an issue with having a
scrollviewer
size itself.
I have the following xaml:
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!--
<Border x:Name="borderLeftColHeader" Grid.Row="0" >
<!--
</Border>
<!--
<Grid Grid.Row="1" x:Name="gridScrollView" Margin="0,0,5,0" >
<ScrollViewer x:Name="svQuestions" VerticalScrollBarVisibility="Auto"
Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}}" >
<!--
<Grid x:Name="gridQuestions" />
</ScrollViewer>
</Grid>
<!--
<Grid Grid.Row="2" Margin="0,0,5,0" >
<!--
</Grid>
<!--
<Grid Grid.Row="3" Margin="0,5,0,0">
<!--
</Grid>
</Grid>
</Grid>
My problem is that if I specifically set the height of the scrollviewer, it displays as expected.
If I used the binding indicated above (
Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}
), it uses the
ActualHeight
of its parent grid which is
always 0.
I also tried binding to the grid's element name (using the same
Path=ActualHeight
).
I also tried adding
SizeChanged
and
UpdatedLayout
event handlers to the parent user control and all related elements so I could inspect the
ActualHeight
of the parent grid (
gridScrollView
) in the debugger, and it's always 0.
I'm out of ideas. What do I need to do to ensure that the
gridScrollView.ActualHeight
gets set to something useful, preferably when the user control gets instantiated?