I am implementing a WPF 4.0 multitouch application, which performs text formatting based on gestures. While I have managed to achieve a few kinds of text formatting, I am having difficulty in realizing text indentation (MS Word style). By MS word style, I mean when left/right indentation is performed:
I found a few solutions, but none seem to work for me at the moment. I use a RichTextBox control, which I have created in my XAML file. I want to perform the text indentation in the code behind. Could someone please let me know how I can achieve this? Thank you.
You mentioned that you want to do this in code behind, but this all can be done in the XAML itself. I imagine you're using C#.
using System.Windows.Documents;
XAML (I'll be using a button example, command could be used anywhere):
<Button Name="increaseIndentButton" Command="EditingCommands.IncreaseIndentation"/>
<Button Name="decreaseIndentButton" Command="EditingCommands.DecreaseIndentation"/>
<RichTextBox Name="myRichTextBox" AcceptsTab="True"/>
Using the EditingCommands
will satisfy all of your requirements listed above.
- If the selected text amounts to a single paragraph (or lesser), indent that whole paragraph.
- If no text is selected, indent the entire paragraph, where the caret is present.
- If the selected text amounts to more than one paragraph, indent all the selected paragraphs entirely. In this case, the paragraphs may be either partially or fully selected.
Moreover, increasing and decreasing indentation have hotkeys, Ctrl+T and Ctrl+Shift+T respectively.
More information is available here: http://msdn.microsoft.com/en-us/library/system.windows.documents.editingcommands(v=vs.100).aspx