Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF UIElements Inline with Text "Adornments"

In WPF how can I put regular UIElements inline with text? For example a certain classification of text would replace a span of text with a dropdown containing specific options.

I've used objects like Span, Bold, Hyperlink that do some light modifications to text inline, but I want to be able to do something more drastic, and custom. Can I implement a similar Inline object to accomplish this?

I am working on a project where I have a need for some advanced text visuals. Specifically I want to do something similar to the Visual Studio 2010 WPF based source editor.

I'll have a piece of text and various components will look at that text searching for pieces with special meaning. When it finds a span of text it will record/mark that span. Then another set of components will go over the classified text and add decorations based on their classifications.

You can kind of think of this like smart tags for WPF.

I really have no idea where to start, all the documentation on advanced text in WPF is about animating, custom brushes, convert to geometry, etc...

like image 244
joshperry Avatar asked Feb 27 '09 03:02

joshperry


1 Answers

Take a look at the InlineUIContainer and BlockUIContainer classes. They allow UIElements to be embedded in a flow content, like FlowDocument or TextBlock.

Here's an example of a Button inlined in a TextBlock:

<TextBlock>
    Some inline
    <InlineUIContainer>
        <Button Content="Hi" Click="Button_Click" />
    </InlineUIContainer>
    inside the text.
</TextBlock>
like image 188
Franci Penov Avatar answered Sep 28 '22 09:09

Franci Penov