html formatting in dynamic text
Hello,
There some cool formatting options here: https://www.noesisengine.com/docs/Gui.C ... orial.html
However, these don't seem to work via bindings defined as so:
When "thatReallyLongText" is set to:
Xaml gets very unhappy when I to use formatting tags directly in text ala:
I have to reformat it to:
However, I'm not terribly sure how to bind it to thatReallyLongText then .. Edit figured it out, but still no html parsing.
Question: I'm wondering what are our options for formatting a text that gets set via a binding?
Edit: Reformating via <textblock> binding didn't work ether, <bold> still just shows up as plain text.
There some cool formatting options here: https://www.noesisengine.com/docs/Gui.C ... orial.html
However, these don't seem to work via bindings defined as so:
Code: Select all
<TextBlock TextWrapping="Wrap"
Style="{StaticResource BodyTextBlock}"
Text="{Binding thatReallyLongText}"
/>
It just shows up with <Bold> right in the text.<Bold>Lorem ipsum dolor sit amet, </Bold> consectetur adipiscing elit. Donec scelerisque justo enim,
Xaml gets very unhappy when I to use formatting tags directly in text ala:
Code: Select all
<TextBlock TextWrapping="Wrap"
Style="{StaticResource BodyTextBlock}"
Text="<Bold>Lorem ipsum dolor sit amet, </Bold> consectetur adipiscing elit. Donec scelerisque justo enim"
/>
Code: Select all
<TextBlock TextWrapping="Wrap"
Style="{StaticResource BodyTextBlock}">
<Bold>Lorem ipsum dolor sit amet, </Bold> consectetur adipiscing elit. Donec scelerisque justo enim"
<TextBlock/>
Question: I'm wondering what are our options for formatting a text that gets set via a binding?
Edit: Reformating via <textblock> binding didn't work ether, <bold> still just shows up as plain text.
Code: Select all
<TextBlock TextWrapping="Wrap"
Style="{StaticResource BodyTextBlock}">
<TextBlock.Text>
{Binding thatReallyLongText}
</TextBlock.Text>
</TextBlock>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: html formatting in dynamic text
Hi,
A TextBlock doesn't directly understand that formatted text. What other clients are doing is creating an attached property or behavior that generates the inlines for the TextBlock. Something like this:
The parsing process and inline generation will be done in the changed callback of that property:
As it is something that has been asked many times we created a ticket in our bugtracker to define a sample behavior doing this: #1963
A TextBlock doesn't directly understand that formatted text. What other clients are doing is creating an attached property or behavior that generates the inlines for the TextBlock. Something like this:
Code: Select all
<TextBlock local:FormattedTextParser.Text="{Binding SomeFormattedText}"/>
Code: Select all
void OnTextChanged(DependencyObject* d, const DependencyPropertyChangedEventArgs& e)
{
TextBlock* textBlock = DynamicCast<TextBlock*>(d);
if (textBlock != nullptr)
{
InlineCollection* inlines = textBlock->GetInlines();
inlines->Clear();
// Parse text...
const String& text = *(const String*)e.newValue;
// Add inlines...
}
}
Re: html formatting in dynamic text
Thank you! Eagerly waiting for #1963
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 43 guests