0

我想要一个自定义的 RichTextBox 控件以在 MS Word 等应用程序中使用。但挑战是对角输入文本。目前,我在 RichTextBox 的 Document 属性中使用 RichTextBox 和 TextEffect 来对角显示文本并且它可以工作。不幸的是,插入符号出现在其原始位置和方向,因此用户会混淆他编辑的内容、输入的位置和选择的内容。你能帮助我吗?

  <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>
4

1 回答 1

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>

您也可以使用旋转变换..也可以使用旋转变换

于 2014-03-06T10:56:20.513 回答