2012-02-26 78 views
0

我有一个TextBlock,我想在30px宽的用户控件中垂直显示。 TextBlock控件已使用RenderTransform旋转90°。TextBlock文字在旋转90度后被截断

当我将它与30px转换结合使用时,旋转似乎很好,但TextBlock的实际内容被截断为30px。

看起来好像文本正在呈现父级的30px宽度然后转换。

<UserControl x:Class="Xyz.Controls.FooControl" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    d:DesignHeight="300" d:DesignWidth="30"> 

    <Grid x:Name="LayoutRoot"> 
     <Grid Name="barGrid" Background="#BFFFFFFF"> 
      <Ellipse Width="30" Height="30" Fill="Red" HorizontalAlignment="Center" VerticalAlignment="Top" /> 
      <TextBlock Name="barText" Text="88.8°" 
         Width="50" 
         Height="30" 
         Foreground="#FF3535C4"> 
       <TextBlock.RenderTransform> 
        <CompositeTransform Rotation="90" TranslateX="30"/> 
       </TextBlock.RenderTransform> 
      </TextBlock> 
     </Grid> 

    </Grid> 
</UserControl> 

在Visual Studio的截图中,期望的文本只显示29px。 Xaml TextBlock content truncated at parent width

Expression Blend和Emulator中出现相同的问题。

+0

我不完全确定,但它可能是一个旋转文本的高度是屏幕的方向的高度,所以30px会截断它。不知道如何解决它,只是一个可能的原因。 – ameer 2012-02-26 03:27:45

+0

更改d:DesignWidth直接更改可以垂直显示的文本数量。例如。增加设计宽度会增加出现的文本数量,反之亦然,同时减小宽度。 – 2012-02-26 05:39:49

回答

2

我已经想出了一种方法来获得预期的布局,但它似乎有点黑客。

通过在TextBlock(-20px)上设置一个等于TextBox宽度(50px)和父宽度(30px)之差的负左边距,垂直显示全文。

E.g.

<TextBlock Name="barText" Text="88.8°" 
        Width="50" 
        Height="30" 
        Foreground="#FF3535C4" 
        Margin="0,0,-20,0"> 
      <TextBlock.RenderTransform> 
       <CompositeTransform Rotation="90" TranslateX="30"/> 
      </TextBlock.RenderTransform> 
     </TextBlock> 
+0

这似乎确实适用于我的问题,但如果有人有更好的答案,我会将接受转移。 – 2012-03-01 22:13:05