Is there any way to set binding in TextBlock Span

I would like to use several Span elements inside a TextBlock and have the contents of the intervals specified by the binding. I do not think this is possible, but at first I wanted to double check.

+4
source share
2 answers

@ walkman123 is correct that you cannot bind to span elements in XAML.

You might want to consider Run elements rather than span elements, as you can bind them to them from a TextBlock .

 <TextBlock FontFamily="Arial" Width="400" Text="Company Information"> <Run FontFamily="Courier New" FontSize="24" Text="{Binding CompanyName}" /> <LineBreak/> <Run FontFamily="Courier New" FontSize="18" FontStyle="Italic" Text="{Binding CompanyAddress}" /> <LineBreak/> <Run FontFamily="Courier New" FontSize="14" FontWeight="Bold" Text="{Binding CompanyPhone}" /> <LineBreak/> </TextBlock> 
+3
source

Yes, the value of the Span cannot be bound because it is not a Framework element, but an inline element.

Only Framework elements can be connected.

+1
source

All Articles