Question

I am trying to have the height of an itemscontrol be set to what is defined in the grid row definitions. If I set the Height on the itemscontrol manually, it of course affects the control. How can I bind to or achieve this behavior? I just want my itemscontrol size to be determined by the grid. Thanks!

<ScrollViewer>

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="600"/>
                <RowDefinition Height="500"/>
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <ItemsControl Grid.Row="1" Grid.Column="0" Name="MIPRegion" cal:RegionManager.RegionName="MIPRegion" />

        </Grid>
    </ScrollViewer>
Was it helpful?

Solution

You can bind to the ActualHeight property of the RowDefinition.

<ScrollViewer>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition x:Name="rowDef0" Height="600"/>
            <RowDefinition x:Name="rowDef1" Height="500"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <ItemsControl Height="{Binding Path=ActualHeight, ElementName=rowDef1}"
                      Grid.Row="1" Grid.Column="0" Name="MIPRegion" 
                      cal:RegionManager.RegionName="MIPRegion" />

    </Grid>
</ScrollViewer>

OTHER TIPS

Try this

I havent use Actualheight and actualwidth for binding as Width and height itself is of type GridLength.

 <ScrollViewer>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="600"/>
            <RowDefinition x:Name="RowHeight" Height="500"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" x:Name="ColumnWidth"/>
        </Grid.ColumnDefinitions>
        <ItemsControl Grid.Row="1" Background="Green" Width="{Binding ElementName=ColumnWidth,Path=Width}" Height="{Binding ElementName=RowHeight,Path=Height}" Grid.Column="0" Name="MIPRegion"  >               
        </ItemsControl>
    </Grid>
    </ScrollViewer> 

In my case RowDefinition's Height was set * and it only worked when I bound the ItemsControl.Height to the Height property, not the ActualHeight. I then realized that such a binding between double and GridLenght is not correct. (Value produced by BindingExpression is not valid for target property.; Value='*' BindingExpression:Path=Height;) But still I confirm that in some case binding to the ActualHeight is not working as expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top