Silverlight切断文本/包装它并且没有正确显示

时间:2009-04-18 16:15:45

标签: silverlight layout silverlight-3.0 expression-blend xamlpad

请帮助我理解这背后的问题并且它已经解决了,我在通过文本显示获得我想要的行为方面遇到了很多麻烦。

TextBlock包含一定长度的字符串,但不会更新控件以显示第二行,实际上会使文本的一部分消失。

这在XamlPad中运行良好,但在Silverlight 3和Expression blend 3中无效

<Grid x:Name="LayoutRoot" Background="{x:Null}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
<Border CornerRadius="20,20,20,20" Grid.ColumnSpan="2" Grid.RowSpan="2" BorderBrush="#FF000000" BorderThickness="1,1,1,1">
    <Border.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FF2100FF"/>
            <GradientStop Color="#FFFFFFFF" Offset="1"/>
        </LinearGradientBrush>
    </Border.Background>
</Border>

<TextBlock x:Name="eventName" Grid.Column="1" Text="Amazing Music" FontSize="24" Margin="5,5,10,5" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0,0,0,0"/>
<TextBlock x:Name="eventDescription" Grid.Column="1" Grid.Row="1" Text="Amazin music in that house" TextWrapping="Wrap" FontSize="14" Margin="5" HorizontalAlignment="Left" VerticalAlignment="Top" MaxWidth="300" />
</Grid>

2 个答案:

答案 0 :(得分:1)

我认为Braulio正在做些什么。通过将文本包装在边框中的堆栈面板中,我能够正确地进行包装和调整大小。将此XAML拖放到没有设置宽度和高度的全新用户控件上。

<Border CornerRadius="20,20,20,20" BorderBrush="#FF000000" BorderThickness="1,1,1,1" 
    Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="192"
    Padding="5">
    <Border.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FF2100FF"/>
            <GradientStop Color="#FFFFFFFF" Offset="1"/>
        </LinearGradientBrush>
    </Border.Background>
    <StackPanel>
        <TextBlock x:Name="eventName" Text="Amazing Music" FontSize="24" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0,0,0,0"/>
        <TextBlock x:Name="eventDescription" Text="Amazin music in that house" TextWrapping="Wrap" FontSize="14" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MaxWidth="300" />
    </StackPanel>
</Border>

答案 1 :(得分:0)

嗯....也许hte isue可以在网格上,尝试在虚拟堆栈面板中执行此操作,只是为了检查您是否必须使用auto或* ...

如果你需要在修复区域内显示TextBlock,那么就可以了。

http://www.tipsdotnet.com/TechBlog.aspx?PageIndex=0&BLID=7

干杯   布劳略