开发者

Xam Grids with varying row size dependant upon data

I am looking to do something with XAML so that the row heights within a grid are variable. But I am not sure if it is possible.

I have two rows in a grid, and if there is data to fill each row then no issue. But, if there is no data to fill the second row then I would like the data in the fist row to be in fact centered using both rows.

I can achieve this by using the Rowspan property, but can I make this dynamic, based upon whether there is data for the row or not?

If not is there any other way for me to achieve this?

Updated code follows.

<StackPanel Grid.Row="0" Grid.Column="4" Grid.RowSpan="2">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="40"/>
                        <RowDefinition Height="25"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Details}" TextWrapping="NoWrap" Style="{StaticResource PhoneTextNormalStyle}" 
                       Grid.Row="0"  Grid.Column="0" Grid.RowSpan="{Binding DetailRowSpan}"  FontSize="{StaticResource PhoneFontSizeMed开发者_JAVA技巧iumLarge}" VerticalAlignment="Center" />

                    <TextBlock Text="{Binding Location}" Style="{StaticResource PhoneTextSmallStyle}"
                       Grid.Row="1" Grid.Column="0"/>

                </Grid>

            </StackPanel>
  • thanks


Set the Height property of the first row to *, and the height property of the second row to Auto:

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

This will make the height of the second row 0 if there is nothing in it. The first row will take up any available space.

EDIT: After re-reading your question and reading the comments, I think that what you are actually asking is how to dynamically make a single cell span multiple rows (or not), depending on whether the next grid has content for that column. If that is the case, then I'd recommend creating a read-only integer property in the class that is bound to the cell whose height might vary. The property should calculate the number of rows that the cell should cover by examining the adjacent rows. It can then be bound to the RowSpan property of the grid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜