Gustavo Guerra
Gustavo Guerra

Reputation: 5359

Difference in behaviour of RowDefinition Height="Auto" with empty TextBlock between WP7 and WP8

I have a DataTemplate used in an ItemsControl that has a grid with 3 rows:

            <Grid Margin="12,0,0,4">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="80" />
                    <ColumnDefinition Width="330" />
                    <ColumnDefinition Width="30"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Text="{Binding Due}" 
                           Foreground="CornflowerBlue" 
                           FontSize="28"
                           HorizontalAlignment="Center" />
                <TextBlock Text="{Binding Expected.Value}" 
                           Foreground="Red" 
                           FontSize="16"
                           Grid.Row="1"
                           Grid.RowSpan="2"
                           HorizontalAlignment="Center" />
                <TextBlock Text="{Binding Destination}" 
                           Grid.Column="1" 
                           FontSize="28"
                           TextWrapping="Wrap"
                           HorizontalAlignment="Left" />
                <TextBlock Text="{Binding Via}" 
                           Grid.Column="1" 
                           Grid.Row="1" 
                           Foreground="Gray"
                           FontSize="16"
                           HorizontalAlignment="Left" />
                <TextBlock Text="{Binding Status}" 
                           Grid.Column="1" 
                           Grid.Row="2" 
                           FontSize="16"
                           HorizontalAlignment="Left" />
                <TextBlock Text="{Binding Platform.Value}" 
                           Grid.Column="2"
                           Grid.RowSpan="3"
                           FontSize="40"
                           VerticalAlignment="Top"
                           HorizontalAlignment="Center" />
            </Grid>

On some of the items, the Via binding will have an empty string, and on WP7 that causes the middle row to collapse. But when I convert the project to WP8, the behaviour is different, I get an empty line, as if it's reserving space for the textblox even though it has no text.

How can I force WP8 to have the same behaviour as WP7 in this scenario?

Upvotes: 0

Views: 270

Answers (1)

Hermit Dave
Hermit Dave

Reputation: 3046

Gustavo,

While I haven't encountered the same issue, I can assure you that WP7 and WP8 occasionally behave differently.

In this particular case, you might want to have a visibility converter on textbox that will toggle the visibility based on the contents of bound text.

Here's a solution to the same http://invokeit.wordpress.com/2013/07/04/converter-to-toggle-visibility-when-content-is-empty-wpdev-wp8dev-wp7dev-win8dev/

Upvotes: 1

Related Questions