【问题标题】:Silverlight, when rotating textbox not all the text showsSilverlight,旋转文本框时并非所有文本都显示
【发布时间】:2011-11-08 21:14:18
【问题描述】:

我有一个自定义控件,里面有一个文本框,它可以根据您希望它折叠还是展开而旋转,当它折叠时我希望文本框是垂直的,当它展开时我希望它是水平的.

问题是当它是垂直的文本框不显示所有文本时,我一直在寻找答案,我知道这与 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();

}

【问题讨论】:

    标签: c# silverlight layout textbox rotatetransform


    【解决方案1】:

    一种解决方案是使用来自Silverlight toolkitLayoutTransformer 控件。

    您将现有的文本块包装在 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;  
    

    【讨论】:

      【解决方案2】:

      我最近遇到了类似的问题,并提出了以下解决方案(基于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();
      }
      

      【讨论】:

        【解决方案3】:

        我刚刚写了以下,我的类似问题已经解决了。

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

        【讨论】:

          猜你喜欢
          • 2012-08-29
          • 2014-06-21
          • 2018-07-14
          • 1970-01-01
          • 1970-01-01
          • 2019-12-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多