Issues with a XAML Label with hard coded text and a binding

2447
3
Jump to solution
08-25-2022 03:28 PM
AbelPerez
Frequent Contributor

Some of these things should be so simple but I end up spending days on it. Really frustrating. 
I looked up examples on how to set a label to hard coded text and a binding.
Something like "Airports found = 3". 

I tried various ways to do this but all I get is just the number.

<Label x:Name="lblAptCount" Content="{Binding Path=DvAirports.Count, StringFormat='Airports found = \{0\}'}"
       ToolTip="Number of airports found near origin airport" HorizontalAlignment="Left" VerticalAlignment="Top" RenderTransformOrigin="1.239,5.789" Margin="0,134,0,0" Width="207"/>


When I use this XAML, the result in the label is just the number like 3.
Can anyone point me in the right direction please.

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

Your StringFormat doesn't work on Labels. You need to use ContentStringFormat or change to TextBlock. More info here:

https://stackoverflow.com/questions/4206612/wpf-stringformat-on-label-content/4209539#4209539 

 

 

View solution in original post

0 Kudos
3 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Your StringFormat doesn't work on Labels. You need to use ContentStringFormat or change to TextBlock. More info here:

https://stackoverflow.com/questions/4206612/wpf-stringformat-on-label-content/4209539#4209539 

 

 

0 Kudos
AbelPerez
Frequent Contributor

@GKmieliauskas thank you! lord have mercy. I checked several articles and I could have sworn I looked only at Labels. Maybe I need more sleep.

0 Kudos
AbelPerez
Frequent Contributor

One more follow up. I wanted to change the label to say "3 airports found". That required an escape sequence {}, otherwise the initial curly brace will not compile.

<Label x:Name="lblAptCount" Content="{Binding Path=DvAirports.Count}" ContentStringFormat="{}{0} airports found"
       ToolTip="Number of airports found near origin airport" HorizontalAlignment="Left" VerticalAlignment="Top" RenderTransformOrigin="1.239,5.789" Margin="0,134,0,0" Width="207"/>

 {} 

0 Kudos