In WPF how can I put regular UIElement
s 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...
Take a look at the InlineUIContainer
and BlockUIContainer
classes. They allow UIElement
s 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With