문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top