How can i get paragraph FlowDirection property (Wpf)

145 views Asked by At

I used this code to find FlowDirection of a Text Range:

 var d=TextRange.GetPropertyValue(Paragraph.FlowDirectionProperty).ToString();
 rtlBtn.IsChecked= d=="RightToLeft";

But it return LeftToRight always, even for Right To Left paragraphs

How can i do that?

1

There are 1 answers

0
mm8 On

But it return LeftToRight always, even for Right To Left paragraphs

No, it doesn't as the following sample demonstrates:

    <RichTextBox x:Name="rtb">
        <FlowDocument>
            <Paragraph FlowDirection="RightToLeft">
                <TextBlock>right to left...</TextBlock>
            </Paragraph>
            <Paragraph FlowDirection="LeftToRight">
                <TextBlock>right to left...</TextBlock>
            </Paragraph>
        </FlowDocument>
    </RichTextBox>

    <CheckBox x:Name="rtlBtn" />
    <Button Content="Click" Click="Button_Click" />

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var textRange = rtb.Selection;
        if(textRange != null)
        {
            var d = textRange.GetPropertyValue(Paragraph.FlowDirectionProperty).ToString();
            rtlBtn.IsChecked = d == "RightToLeft";
        }
    }

You need to make sure that the TextRange belongs the Paragraph that you expected and that the property of this reallu is set to RightToLeft.