文本块在XAML中相互重叠

时间:2014-11-27 08:32:41

标签: c# xaml windows-phone-8

这是我想要获得的:

Name
Date

这是我的XAML。但在结果中,两个文本名称&日期相互重叠。

<DataTemplate>
    <Grid x:Name="showGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <StackPanel>
            <Grid Height="{Binding widthMA}" Width="{Binding widthMA}">
                <Grid Margin="3.5" Background="White">                                                                
                    <Grid VerticalAlignment="Bottom" Background="Black" Height="30">
                        <TextBlock Text="{Binding strName}" Style="{StaticResource AlbumTitleText}" Grid.Row="0" />
                        <TextBlock Text="{Binding dateCreated}" Style="{StaticResource ArtistTitleText}" Grid.Row="1" />
                    </Grid>
                </Grid>
            </Grid>
        </StackPanel>                                                
    </Grid>
</DataTemplate>

样式AlbumTitleTextArtistTitleText就在这里

<Style x:Key="AlbumTitleText" TargetType="TextBlock">
    <Setter Property="Foreground" Value="White" />
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="FontSize" Value="18" />
    <Setter Property="FontFamily" Value="Fonts/Gotham-Bold.ttf#Gotham Bold" />
    <Setter Property="TextTrimming" Value="CharacterEllipsis" />
    <Setter Property="FontWeight" Value="Bold" />            
    <Setter Property="Margin" Value="10,-2,10,7"></Setter>
</Style>

<Style x:Key="ArtistTitleText" TargetType="TextBlock">
    <Setter Property="Foreground" Value="White" />
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="FontSize" Value="16" />
    <Setter Property="FontFamily" Value="Fonts/Gotham-Bold.ttf#Gotham Bold" />
    <Setter Property="TextTrimming" Value="CharacterEllipsis" />
    <Setter Property="FontWeight" Value="Normal" />
    <Setter Property="Margin" Value="10,7,10,0"></Setter>
</Style>

1 个答案:

答案 0 :(得分:3)

我认为您的行定义位置错误。试试......

<DataTemplate>
     <Grid x:Name="showGrid">
         <StackPanel>
            <Grid Height="{Binding widthMA}" Width="{Binding widthMA}">
                <Grid Margin="3.5" Background="White">                                                                
                    <Grid VerticalAlignment="Bottom" Background="Black" Height="30">
                         <Grid.RowDefinitions>
                             <RowDefinition Height="Auto"/>
                             <RowDefinition Height="Auto"/>
                          </Grid.RowDefinitions>
                        <TextBlock Text="{Binding strName}" Style="{StaticResource AlbumTitleText}" Grid.Row="0" />
                        <TextBlock Text="{Binding dateCreated}" Style="{StaticResource ArtistTitleText}" Grid.Row="1" />
                    </Grid>
                </Grid>
            </Grid>
        </StackPanel>                                                
    </Grid>
</DataTemplate>