如何放置高度="高度窗口 - 高度控制"

时间:2018-06-07 23:45:19

标签: wpf xaml

我希望我的ScrollvViewer的高度是窗口高度减去其他StackPanel的高度。我得到窗口的高度:

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

但是我可以通过示例来减去它100 ..

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

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

2 个答案:

答案 0 :(得分:0)

的Xaml:

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

转换器:

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" );
     }
}

答案 1 :(得分:0)

如果ScrollViewer位于网格的最后一行,则设置行高如下:

<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>

假设网格将使用窗口的完整客户区域,最后一行将使用堆栈面板声称其高度后剩余的任何高度。