WPF UIElements Inline with Text "Adornments"
Asked Answered
F

1

7

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...

Flavorous answered 27/2, 2009 at 3:20 Comment(0)
K
13

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>
Klemens answered 27/2, 2009 at 5:27 Comment(2)
Thank you my friend! You are a beautiful, beautiful person; and don't let anyone tell you otherwise!Flavorous
Wow WPF is seriously the best thing Microsoft has ever created, and the bes ui framework I've used (ex-cocoa guy here heehee)Shanghai

© 2022 - 2024 — McMap. All rights reserved.