Search code examples
wpfgridtabcontrolrowdefinitionelement-binding

wpf height and width by element binding


wpf height and width of control based on rowheight and rowwidth of grid by element binding to it.

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

In the above code it is taking MaxHeight=0. But what i need is it should take that based on ContentControlRow's Height and it should be variable based on Window size.


Solution

  • Change ActualHeight to Height in Binding.

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