Amsakanna
Amsakanna

Reputation: 12934

Block Select in TextBox/RichTextBox

I'm developing a notepad clone. I would like to implement a block select as in textpad (vertical selection). How would I do that?

Textpad Block Select

EDIT: I don't know what kind of detail should be added to this question. However this is my code. I need to add block select functionality to this textbox.

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

Upvotes: 4

Views: 678

Answers (1)

Eli Arbel
Eli Arbel

Reputation: 22739

You can use AvalonEdit. It's a native WPF editor that has this feature and many more.

Upvotes: 3

Related Questions