Reputation: 18799
So I have a label which is bound to some text in my view model like so:
<Label VerticalOptions="Center" Text="{Binding Note, StringFormat='"{0}"'}" Style="{StaticResource ListItemSubTitleStyleDefault}" LineBreakMode="WordWrap" FontAttributes="Italic"/>
And I am trying to get the note to be surrounded in quotation marks like so
"I am a Note"
looking at some WPF
answers it suggested using the following in the StringFormat
property '"{0}"'
But this doesn't seem to work. Does anyone know how to surround a Labels
text in quotation marks in Xamarin.Forms?
Upvotes: 2
Views: 2649
Reputation: 4032
On the code from your ViewModel you can also do this:
string _note;
public string Note => string.Format("\"{0}\"", _note);
I hope this helps.
Upvotes: 0
Reputation: 2934
As you've seen, Xamarin.Forms is different from WPF for this case. For Xamarin, do this:
<Label VerticalOptions="Center" Text="{Binding Note, StringFormat='{}"{0}"'}" .../>
In order to prevent the runtime from ignoring the double quotes, the first double quote either has to be escaped (as above), or it can't immediately follow the single quote (see below).
So for example, throwing in a space in between works as well:
<Label VerticalOptions="Center" Text="{Binding Note, StringFormat=' "{0}"'}" .../>
With this latter solution, there will be at least one character rendered before the double quote.
Upvotes: 4