Home Forums WPF controls Other WPF controls Xceed RichTextBox Vertical Alignment

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • dhaval
    Post count: 1
    #44949 |

    How to align a text vertically using Xceed.Richtextbox.

    Sample for horizontal alignment as Left:

    var richTextBox = obj as Xceed.Wpf.Toolkit.RichTextBox;
     var selectedText = richTextBox.Selection;
    selectedText.ApplyPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Left);

    May i know the property to be used for aligning a text Vertically as Top,Middle,Bottom.
    I tried Richtextbox properties: VerticalAlignment, VerticalContentAlignment: But these didn’t work

    Fawzi [Xceed]
    Post count: 722


    Using a standard WPF RichTextBox with HorizontalContentAlignment and VerticalContentAlignment will not work, by design.

    The Xceed.RichTextBox derives from the standard WPF RichTextBox, so the HorizontalContentAlignment and verticalContentAlignment will still don’t work.

    Here are potential solutions :
    For Horizontal alignment, as you do, try setting the Document.TextAlignment :

    _RichTextBox.Document.TextAlignment = TextAlignment.Right;

    For vertical alignment, try modifying the TextBoxBase ControlTemplate so that the ScrollViewer will template bind the VerticalContentAlignment :

    <Style x:Key=”AlignedTextBoxBaseStyle”
    BasedOn=”{StaticResource {x:Type TextBoxBase}}”>
    <Setter Property=”Template”>
    <ControlTemplate TargetType=”{x:Type TextBoxBase}”>
    <Border x:Name=”border” BorderBrush=”{TemplateBinding BorderBrush}” BorderThickness=”{TemplateBinding BorderThickness}” Background=”{TemplateBinding Background}” SnapsToDevicePixels=”True”>
    <ScrollViewer x:Name=”PART_ContentHost” Focusable=”false” HorizontalScrollBarVisibility=”Hidden” VerticalScrollBarVisibility=”Hidden” VerticalAlignment=”{TemplateBinding VerticalContentAlignment}”/>

    <xctk:RichTextBox x:Name=”_RichTextBox”
    Style=”{StaticResource AlignedTextBoxBaseStyle}”>

    You will then be able to do :
    _RichTextBox.VerticalContentAlignment = VerticalAlignment.Bottom;

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.