I have an extension for textblock, to allow formatted "Inlines" to be assigned. I've followed the approach provided by @max to create this extension.
Format part of the text of TextBlock using iValueConverter
Now, what I need to do is to be able to set this FormattedText property programmatically as the UI element, which is the parent of the TextBlock is being created dynamically.
<TextBlock FontSize="14" FontFamily="Calibri" local:TextBlockEx.FormattedText="{Binding Converter={StaticResource LabelFormatConerter}}" />
Have you tried using the methods that were clearly declared in the answer to your linked question, or do you copy without looking? Maybe something like this?:
TextBlockEx textBlockEx = new TextBlockEx();
textBlockEx.SetFormattedText(textBlockEx, new Run() { Text = "Hello World" });
UPDATE >>>
You really should ask every thing at once, rather than asking additional questions once your question had been answered. I can 't even provide a full answer to your second question, as you removed the Binding.Path
and Source
from the Binding
. To create your Binding
in code:
Binding binding = new Binding("PropertyOfYourDataSourceObject");
binding.Source = YourDataSourceObject;
binding.Converter = new SomeConverter();
textBlockEx.SetBinding(TextBlockEx.FormattedTextProperty, binding);
Please refer to the How to: Create a Binding in Code page on MSDN for further help.