Silverlight 切断文本/将其换行并且无法正确显示

发布于 2024-07-17 11:57:11 字数 1439 浏览 7 评论 0原文

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

对于一定长度的字符串,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>

Please help me understand the issue behind this and it's fix, I'm having agood deal of trouble getting the behaviour I want with text display.

With certain lengths of strings the TextBlock wraps around, but does not update the control to show the second line, in effect making part of the text dissappear.

This works fine in XamlPad, but not in Silverlight 3 and 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿咻 2024-07-24 11:57:11

我认为布劳略说对了。 通过将文本包装在边框中的堆栈面板中,我能够正确地包装和调整大小。 将此 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>

I think Braulio's onto something. I was able to get it to wrap and size correctly by wrapping the text in a stackpanel in a border. Drop this XAML onto a brand-new user control that does not have a width and height set.

<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>
我要还你自由 2024-07-24 11:57:11

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

另一方面,如果您需要显示 TextBlock在修复区域内,

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

干杯
布劳略

Mmm.... maybe hte isue can be on the Grid, try to do that in a dummy stack panel, just to check whether you have to play with auto or * ...

On the ohter hand if you need to show a TextBlock inside a fix area,

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

Cheers
Braulio

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文