Silverlight,当旋转文本框时并非所有文本显示

时间:2011-11-08 21:14:19

标签: c# silverlight layout textbox rotatetransform

我有一个自定义控件内部我有一个文本框可以根据你想要它折叠或展开而旋转,当它折叠时我希望文本框是垂直的,当它被展开时我希望它是水平的

问题是,当它是垂直的时,文本框不显示所有文本,我一直在寻找答案,我理解它与silverlight更新它的布局的方式有关。这是我的代码

private void CollapseControl()
{
    CollapseCommand.Content = "E";            
    CollapseCommand.Margin = _btnMarginOnCollapse;

    BtnZoomIn.Visibility = Visibility.Collapsed;
    BtnZoomOut.Visibility = Visibility.Collapsed;
    ScrollViewerStackPanel.Visibility = Visibility.Collapsed;
    ZoomPanel.Visibility = Visibility.Collapsed;

    this.HorizontalAlignment = HorizontalAlignment.Left;
    this.Width = 40;

    RotateTransform nameRotateTransform = new RotateTransform();
    nameRotateTransform.Angle = 270;            
    Nametb.RenderTransform = nameRotateTransform;            
    Nametb.VerticalAlignment = VerticalAlignment.Bottom;
    Nametb.Height = Nametb.Width;
    Nametb.Width = Nametb.Height;
    Nametb.UpdateLayout();

}

3 个答案:

答案 0 :(得分:3)

一种解决方案是使用Silverlight toolkit中的LayoutTransformer控件。

将现有文本块包装在LayoutTransformer

        <toolkit:LayoutTransformer x:Name="Namelt" ...>
            <toolkit:LayoutTransformer.LayoutTransform>
                <RotateTransform />
            </toolkit:LayoutTransformer.LayoutTransform>
            <TextBlock x:Name="Nametb" Text="Hello World" />
        </toolkit:LayoutTransformer>

然后您的代码如下: -

((RotateTransform)Namelt.LayoutTransform).Angle = 270;                         
Namelt.VerticalAlignment = VerticalAlignment.Bottom;     
Namelt.Height = Nametb.Width;     
Namelt.Width = Nametb.Height;  

答案 1 :(得分:0)

我刚刚遇到了类似的问题,并提出了以下解决方案(基于a post on the Silverlight forums),这对您的问题也有帮助:

private void CollapseControl()
{
    CollapseCommand.Content = "E";
    CollapseCommand.Margin = _btnMarginOnCollapse;

    BtnZoomIn.Visibility = Visibility.Collapsed;
    BtnZoomOut.Visibility = Visibility.Collapsed;
    ScrollViewerStackPanel.Visibility = Visibility.Collapsed;
    ZoomPanel.Visibility = Visibility.Collapsed;

    this.HorizontalAlignment = HorizontalAlignment.Left;

    LayoutTransform lt = new LayoutTransform();
    lt.Content = Nametb;

    RotateTransform nameRotateTransform = new RotateTransform();
    nameRotateTransform.Angle = 270;

    lt.LayoutTransform = nameRotateTransform;
    lt.ApplyLayoutTransform();
    Nametb.UpdateLayout();
}

答案 2 :(得分:0)

我刚刚写了下面的内容,我的类似问题也解决了。

layoutTransform.VerticalAlignment = VerticalAlignment.Bottom;
layoutTransform.VerticalAlignment = VerticalAlignment.Center;