wpf由元素绑定的高度和宽度

时间:2018-01-25 04:47:23

标签: wpf

wpf控件的高度和宽度,基于网格的行高和行宽 元素绑定

 <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="170" />
            <RowDefinition Height="*"   x:Name="ContentControlRow"/>
            <RowDefinition Height="170"/>
        </Grid.RowDefinitions>
        <TabControl Grid.Row="1" x:Name="Tab" MaxHeight="{Binding   ElementName=ContentControlRow, Path=ActualHeight}" Background="Red" VerticalAlignment="Stretch">
            <TabItem>
            </TabItem>
        </TabControl>
    </Grid>

在上面的代码中,MaxHeight = 0。但我需要的是它应该采取基于ContentControlRow的高度,它应该是基于窗口大小变量。

1 个答案:

答案 0 :(得分:0)

在绑定中将ActualHeight更改为高度。

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="170" />
            <RowDefinition Height="*"   x:Name="ContentControlRow"/>
            <RowDefinition Height="170"/>
        </Grid.RowDefinitions>
        <TabControl Grid.Row="1" x:Name="Tab" MaxHeight="{Binding   ElementName=ContentControlRow, Path=Height}" Background="Red" VerticalAlignment="Stretch">
            <TabItem>
            </TabItem>
        </TabControl>
</Grid>
相关问题