-1

I am trying to format parts of the text something like 'this is test'. where parts of the string are bold and in italic. I get the string as a collection of words {word1, word2, word3......}

<Button Command="{Binding MyCommand}" CommandParameter="{Binding Text, ElementName=MyTextBlock}">
<TextBlock src:TextHelper.FormattedText="{Binding ListOfWords}" Name="MyTextBlock"/>

And in the helper i am parsing through the collection of words and i am setting the inline with the formatting which is working fine i.e. i see the correctly formatted text on the UI

textBlock.Inlines.Add(span);

But when the button is clicked the first time i don't get any value because the text property of the text block is empty.

I came across a similar question

Read C# Textblock Text Property filled using Inlines

But I cannot use loaded method. Is there some way to get the value of text and pass to the command ?

Community
  • 1
  • 1
Kaddy
  • 1,226
  • 7
  • 21
  • 34

1 Answers1

0

Use a reference as follows

 CommandParameter="{Binding Text, Source={x:Reference MyTextBlock}}"

or (passing the whole TextBlock)

 CommandParameter="{Binding Source={x:Reference MyTextBlock}}"

In addition, you could also make the Command async and await a certain number of Task.Delay till the property gets filled.