RichTextBox带有对角线文本行

时间:2014-03-06 10:34:36

标签: wpf richtextbox rotatetransform

我想要在MS Word等应用程序中使用自定义的RichTextBox控件。但挑战是对角输入文本。目前,我在RichTextBox的Document属性中使用了RichTextBox和TextEffect for Runs来对角显示文本并且它可以正常工作。不幸的是,插入符号出现在其原始位置和方向上,因此用户将对他编辑的内容,他键入的内容和他选择的内容感到困惑。你能救我吗?

  <Style TargetType="Run">
    <Setter Property="TextEffects">
      <Setter.Value>
        <TextEffectCollection>
          <TextEffect PositionCount="99999">
            <TextEffect.Transform>
              <TransformGroup>
              <ScaleTransform/>
              <SkewTransform/>
              <RotateTransform Angle="30"/>
              <TranslateTransform X="30" Y="0"/>
            </TransformGroup>
          </TextEffect.Transform>
         </TextEffect>
       </TextEffectCollection>
      </Setter.Value>
    </Setter>
  </Style>

1 个答案:

答案 0 :(得分:1)

希望这个帮助

<Window.Resources>
    <Style TargetType="RichTextBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBoxBase}">
                    <Grid>
                        <Border Name="Border" Padding="1" BorderThickness="1" Background="Transparent" BorderBrush="Gray">
                            <ScrollViewer Margin="0" x:Name="PART_ContentHost" >
                                <ScrollViewer.RenderTransform>
                                    <RotateTransform Angle="45"></RotateTransform>
                                </ScrollViewer.RenderTransform>
                            </ScrollViewer>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="Border" Property="BorderBrush" Value="Black"></Setter>
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter TargetName="Border" Property="BorderBrush" Value="Black"></Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid>
    <RichTextBox Height="300" Width="300">
        <RichTextBox.Document>
            <FlowDocument>
                <Paragraph>
                    <Run>
                    </Run>
                </Paragraph>
            </FlowDocument>
        </RichTextBox.Document>
    </RichTextBox>
</Grid>

<强>更新

<Window.Resources>
    <Style TargetType="RichTextBox">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBoxBase}">
                    <Grid>
                        <Border Name="Border" Padding="1" BorderThickness="1" Background="Transparent"  BorderBrush="Gray">
                            <ScrollViewer  x:Name="PART_ContentHost" Margin="0" ScrollViewer.VerticalScrollBarVisibility="Auto">
                                <ScrollViewer.LayoutTransform>
                                    <SkewTransform AngleY="20"/>
                                </ScrollViewer.LayoutTransform>
                            </ScrollViewer>
                        </Border>
                        <TextBlock TextWrapping="Wrap">
                            <ContentPresenter></ContentPresenter>
                        </TextBlock>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="Border" Property="BorderBrush" Value="Black"></Setter>
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter TargetName="Border" Property="BorderBrush" Value="Black"></Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

你也可以使用旋转变换..还有旋转变换