块选择TextBox / RichTextBox

时间:2012-05-12 12:46:03

标签: wpf textbox richtextbox notepad

我正在开发一个记事本克隆。我想在textpad中实现一个块选择(垂直选择)。我该怎么做?

Textpad Block Select

编辑: 我不知道应该在这个问题上添加什么样的细节。不过这是我的代码。我需要在此文本框中添加块选择功能。

<TextBox Name="txtContentBox"
         Text="{Binding Content, UpdateSourceTrigger=PropertyChanged}"
         VerticalAlignment="Stretch"
         Background="White"
         Foreground="#111111"
         BorderThickness="0"
         FontSize="{Binding FontSize}"
         FontFamily="{Binding CurrentFont}"
         FontStyle="{Binding IsItalic, Converter={StaticResource BoolToFontStyle}, ConverterParameter=Italic}"
         FontWeight="{Binding IsBold, Converter={StaticResource BoolToFontWeight}, ConverterParameter=Bold}"
         TextWrapping="{Binding IsWrap, Converter={StaticResource BoolToWrap}}"                                                          
         SelectionBrush="#6674AAE2"                             
         AcceptsReturn="True"
         AcceptsTab="True"
         VerticalScrollBarVisibility="Auto"
         HorizontalScrollBarVisibility="Auto"                             
         AllowDrop="True"
         SnapsToDevicePixels="False"
         MouseMove="txtContentBox_MouseMove"
         PreviewMouseDown="txtContentBox_PreviewMouseDown"
         PreviewMouseUp="txtContentBox_PreviewMouseUp">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="TextChanged">
            <cmd:EventToCommand Command="{Binding HandleChangesCommand}" />
        </i:EventTrigger>
        <i:EventTrigger EventName="PreviewMouseWheel">
            <cmd:EventToCommand Command="{Binding IncDecFontSizeCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
        <i:EventTrigger EventName="Drop">
            <cmd:EventToCommand Command="{Binding OpenCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
        <i:EventTrigger EventName="PreviewDragEnter">
            <cmd:EventToCommand Command="{Binding PreviewDraggedFileCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
        <i:EventTrigger EventName="PreviewDragOver">
            <cmd:EventToCommand Command="{Binding PreviewDraggedFileCommand}"
                                PassEventArgsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</TextBox>

1 个答案:

答案 0 :(得分:3)

您可以使用AvalonEdit。它是一个原生的WPF编辑器,具有此功能以及更多功能。