我有一个自定义控件,其中有一个文本框,可以旋转,具体取决于您希望它折叠还是展开,折叠时我希望文本框是垂直的,展开时我希望它水平的.
问题是,当它是垂直的时,文本框不会显示所有文本,我一直在寻找答案,并且我知道这与 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();
}
最佳答案
一种解决方案是使用 Silverlight toolkit 中的 LayoutTransformer
控件。 .
将现有文本 block 包装在 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;
关于c# - Silverlight,旋转文本框时并非所有文本都显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8057148/