0

我在 ItemsControl 中使用了一个 DataTemplate,它有一个 3 行的网格:

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

在某些项目上,Via 绑定将有一个空字符串,而在 WP7 上会导致中间行折叠。但是当我将项目转换为 WP8 时,行为有所不同,我得到一个空行,好像它为 textblox 保留空间,即使它没有文本。

在这种情况下,如何强制 WP8 具有与 WP7 相同的行为?

4

1 回答 1

1

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/

于 2013-06-11T23:25:01.140 回答