Search code examples
stringxamarin.formsstring-formatting

Strings containing `{` needs to be escaped. Start the string with `{}`"


In my Xamarin project I have a Label that formats a Date Value. I updated some Xamarin Nuget packages and now I'm getting the following error:

Strings containing { needs to be escaped. Start the string with {}"

The Label on the page is a pretty simple StringFormat

<Label Text="{Binding Booking.ScheduledDeparture, StringFormat='{0:dd/MM/yyyy}'}"/>

Any ideas how I can resolve this error. I've tried adding @ to the start of the StringFormat but that didn't work.


Solution

  • Add a {} before a string that starts with a { this should escape it. So '{}{0:dd/MM/yyyy}'. For more documentation: https://learn.microsoft.com/en-us/dotnet/framework/xaml-services/escape-sequence-markup-extension