How do I escape a comma when using a markup extension?
Asked Answered
T

1

11

The value of the second parameter of the markup extension I am using is a string containing some commas and I don't want those commas to be interpreted as parameter separators by the xaml interpreter / parser, but that the whole string as such including the commas is used as value.

Here is an example:

<SomeControl SomeProperty="{Wpf:MyExtension MyFirstParameter, 
                                            MySecondParameter, being a string, containing some commas.}" />

Google didn't help, I found some similar issues but none apply to this problem:

Transcend answered 10/1, 2012 at 14:12 Comment(0)
D
18

You can use single quotes to encapsulate a string; so your mark-up should look something like:

<SomeControl SomeProperty="{Wpf:MyExtension MyFirstParameter, 
                           'MySecondParameter, being a string, containing some commas.'}" />

I'm not sure whether you will also need the {} escape sequence mark-up.

Deserving answered 10/1, 2012 at 14:21 Comment(2)
And I thought I tried that... Thanks a lot, that does the job.Transcend
You do still need a leading {} if a left brace immediately follows the left apostrophe. I just had this exact case and it won't even compile without it. E.g., '{}{0:N0}, that is cool'Compossible

© 2022 - 2024 — McMap. All rights reserved.