使用标记扩展时如何转义逗号?

时间:2022-05-25 16:49:40

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.

我正在使用的标记扩展的第二个参数的值是一个包含一些逗号的字符串,我不希望这些逗号被xaml解释器/解析器解释为参数分隔符,但整个字符串都包含逗号用作值。

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:

谷歌没有帮助,我发现了一些类似的问题,但没有一个适用于这个问题:

1 个解决方案

#1


15  

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.

我不确定你是否还需要{}转义序列标记。

#1


15  

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.

我不确定你是否还需要{}转义序列标记。