LandonSchropp
LandonSchropp

Reputation: 10274

TextBox Partially Editable

Is it possible to make the contents of a TextBox or a RichTextBox parially editable? For instance, I would like to have something that looks like the following:

<TextBox TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" FontFamily="Courier New" Margin="10,0">
    This text and anything before it isn't editable.

    This Text is Editable

    This text and anything after it is not editable.
</TextBox>

or something like this:

<RichTextBox AcceptsReturn="True" VerticalScrollBarVisibility="Auto" FontFamily="Courier New" Margin="10,0">
    <FlowDocument>
        <Paragraph>This text and anything before it is not editable.</Paragraph>
        <Paragraph>This text is editable.</Paragraph>
        <Paragraph>This text and anything after it is not editable.</Paragraph>
    </FlowDocument>
</RichTextBox>

Ideally, I would be able to style the editable text different than the uneditable text. Before anybody tells me I shouldn't do this, I have a valid reason for doing it.

Thanks in advance.

Upvotes: 1

Views: 1039

Answers (2)

Michael Madsen
Michael Madsen

Reputation: 55009

You should be able to encapsulate the three controls into a scrollable region and resize your editable field as needed (i.e., the editable field has no scrolling, only the containing region).

It's not very pretty, especially if there isn't an easy way of doing it with XAML (I've never used it, so I can't say), but I would content it's far better than trying to hack this thing into (Rich)TextBox.

Upvotes: 3

Vinit Sankhe
Vinit Sankhe

Reputation: 19895

A textBox with its Template overrriden to hide its border and 2 textblocks of same look and feel put ahead and post the textbox in that Template can achieve what you seek.

Default textbox template which you can override is here...

Upvotes: 2

Related Questions