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.
Solved! Go to Solution.
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
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
@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.
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"/>
{}