问题是:如何在没有旋转TextBox本身的情况下旋转WPF TextBox 中的文本?的 (Rotate text only)
我尝试了不同的RenderTransforms,LayoutTransforms,但这对我没有帮助。
答案 0 :(得分:1)
找到答案我自己:将TextBox放在其他控件中,即在RIchTextBox中:
<RichTextBox>
<FlowDocument>
<Paragraph>
<TextBlock Text="Stacked text!">
<TextBlock.LayoutTransform>
<RotateTransform Angle="-90"></RotateTransform>
</TextBlock.LayoutTransform>
</TextBlock>
</Paragraph>
</FlowDocument>
</RichTextBox>
答案 1 :(得分:1)
我想说问题的正确解决方案是为ControlTemplate
定义自定义TextBox
并将RotateTransform
应用于ScrollViewer
元素:
<TextBox Background="Yellow" Text="test">
<TextBox.Template>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<ScrollViewer.LayoutTransform>
<RotateTransform Angle="-90"></RotateTransform>
</ScrollViewer.LayoutTransform>
</ScrollViewer>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="#FF7EB4EA"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="#FF569DE5"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</TextBox.Template>
</TextBox>