Kapparino
Kapparino

Reputation: 988

Styling text part in flow document

I have defined following in my XAML file:

<FlowDocumentScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
    <FlowDocument Name="FlowDocument1" PagePadding="10" FontFamily="Segoe UI" FontSize="22">
        <Paragraph>
            Those who have denied the reality of moral distinctions, may be
            ranked among the disingenuous disputants; nor is it conceivable,
            that any human creature could ever seriously believe, that all
            characters and actions were alike entitled to the affection and
            regard of everyone. The difference, which nature has placed
            between one man and another, is so wide, and this difference is
            still so much farther widened, by education, example, and habit,
            that, where the opposite extremes come at once under our
            apprehension, there is no scepticism so scrupulous, and scarce
            any assurance so determined, as absolutely to deny all
            distinction between them. Let a man's insensibility be ever so
            great, he must often be touched with the images of Right and
            Wrong; and let his prejudices be ever so obstinate, he must
            observe, that others are susceptible of like impressions. The
            only way, therefore, of converting an antagonist of this kind, is
            to leave him to himself.
        </Paragraph>
    </FlowDocument>
</FlowDocumentScrollViewer>

How can I in C#, for some text part defined in this paragraph, change background color or make it bold or italic ?

Upvotes: 1

Views: 1634

Answers (1)

DidIReallyWriteThat
DidIReallyWriteThat

Reputation: 1033

The short answer is to treat your code like an xml file if you are familar with Nodes. The flow document is made up of blocks, with paragraphs, lines, etc.

http://www.codeproject.com/Articles/37368/WPF-Flow-Document-For-Beginners

So for example. your FlowDocument doesn;t have a name, so let's call it flowDocument1, so

flowDocument1.Blocks.Paragraph.Text = "Here"

Upvotes: 1

Related Questions