1

I want that the height of my ScrollvViewer, be window height minus height others StackPanel. I get the height of the window with:

<ScrollViewer Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Border}}, Path=ActualHeight}" >

But I can't subtrac it 100, by example..

<ScrollViewer Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Border}}, Path=ActualHeight}" -100 >

or

<ScrollViewer Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Border}}, Path=ActualHeight} - {Binding ActualHeight, ElementName=parentElementName}">
Ivancho
  • 25
  • 3
  • Have a look at IValueConverter. – Swamy Jun 08 '18 at 00:02
  • Check [here](https://stackoverflow.com/questions/50747985/c-sharp-change-property-value-before-binding) for an example of IValueConverter implementation that subtract some value to another double property. Note that your converter will need to subclass MarkupExtension in order to use it in XAML and have Intellisense. Just `return this;` in the ProvideValue method. – Roger Leblanc Jun 08 '18 at 03:20

2 Answers2

0

Xaml:

<ScrollViewer Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Border}}, Path=ActualHeight}, Converter={StaticResource minusHundredConverter}" >

Converter:

public class MinusHundredConverter: IValueConverter
{
     public object Convert(object value, Type targetType,object parameter, CultureInfo culture )
     {
         return ((double)value) - 100;
     }

     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture )
     {
         throw new NotSupportedException( "Cannot convert back" );
     }
}
Swamy
  • 343
  • 2
  • 12
0

If the ScrollViewer is in the last row of a Grid set the row heights like this:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <StackPanel Grid.Row="0">...</StackPanel>
    <StackPanel Grid.Row="1">...</StackPanel>
    <StackPanel Grid.Row="2">...</StackPanel>
    <ScrollViewer Grid.Row="3">...</ScrollViewer>
</Grid>

Assuming the Grid will use the full client area of the Window, the last row will use whatever height is remaining after the stack panels have claimed their heights.

Emond
  • 50,210
  • 11
  • 84
  • 115