I am trying to nest a user control within a ScrollViewer making its height the same as height of the ScrollViewer, which may vary based on screen size (i.e. not fixed).
The ScrollViewer is responsible for horizontal scrolling and has vertical scrolling disabled. The nested user control has a grid with two rows - "header" (another user control) and a ListView. This ListView should be vertically scrollable. The objective here is that the "header" stays in place and large content of the ListView is scrollable vertically. Otherwise, if the containing ScrollViewer is responsible for vertical scrolling, the "header" will go out of visible area on vertical scrolling of the ScrollViewer.
My question is: how can I make nested user control's height the same as the height of the ScrollViewer (which is not fixed)? If nested user control's height is not specified/constrained (equal to 540 in the snippet below), the ListView takes all the space it needs and thus it is not scrollable vertically. In other words, I think I need to remove hard-coded height "540" from the and somehow make its height the same as its parent (ScrollViewer). There might be a better solution, but constraining height of the user control seems to be one way to achieve the objective.
Here is the relevant XAML of the page with ScrollViewer:
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row ="1">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollMode="Disabled" VerticalScrollBarVisibility="Hidden">
<userCtrl:MyUserControl Height="540"/>
</ScrollViewer>
</Grid>
Here is XAML snippet of the user control
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="120"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<local:HeaderRow x:Name="headerRow"></local:HeaderRow>
<ListView x:Name="gridBodyListView" Grid.Row="1 "/>
</Grid>