Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I escape a single quote in a XAML markup extension property literal?

I have a value converter that formats numbers (I can't use SP1 yet unfortunately). It works fine until it gets a percentage.

Here's an example:

<TextBlock Text="{Binding Path=PercentageComplete,
                          Converter={StaticResource NumberFormatter},
                          ConverterParameter='0.00 %'}" />

Unfortunately for me when Double.ToString sees a percentage character, it multiplies the number by 100. In my case, the number is already a percentage and no conversion is needed.

In C#, this would be achieved by escaping the % character with a single quote:

(99.99).ToString("0.00 %")  // gives -> "9999 %"
(99.99).ToString("0.00 '%") // gives -> "99.99 %"

Unfortunately, I cannot use a single quote in the ConverterParameter in the above XAML markup extension. Is there a way of escaping it? I have tried doubling the single quotes and using a backslash, but both failed to compile.

like image 536
Drew Noakes Avatar asked Aug 25 '09 20:08

Drew Noakes


1 Answers

Untested, but have you tried:

<TextBlock Text="{Binding Path=PercentageComplete,
                      Converter={StaticResource NumberFormatter},
                      ConverterParameter=&quot;0.00 '%&quot;}" />
like image 111
Rowland Shaw Avatar answered Sep 28 '22 04:09

Rowland Shaw