alansiqueira27
alansiqueira27

Reputation: 8506

RichTextBox Default Value?

Is there any property to I define the default value in richtextbox?

I mean, by default the text is like this: "Type what you want", and when the user clicks, this word dissapear.

Thanks

Upvotes: 0

Views: 2257

Answers (1)

David Morton
David Morton

Reputation: 16505

A RichTextBox contains a FlowDocument. You have to add a FlowDocument of some kind to the RichTextBox in order to get default text in the document.

To get the text to disappear when you click on it, simply handle the GotFocus event, and reset the FlowDocument.

Try doing something like this:

<RichTextBox GotFocus="RichTextBox_GotFocus">
    <RichTextBox.Document>
        <FlowDocument>
            <FlowDocument.Blocks>
                <Paragraph>
                    Type what you want
                </Paragraph>
            </FlowDocument.Blocks>
        </FlowDocument>
    </RichTextBox.Document>
</RichTextBox>

And in the .cs file:

private void RichTextBox_GotFocus(object sender, RoutedEventArgs e)
{
    ((RichTextBox)sender).Document = new FlowDocument();
}

Upvotes: 1

Related Questions