Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I escape a comma when using a markup extension?

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:

  • http://msdn.microsoft.com/de-de/library/ms744986.aspx
  • http://msdn.microsoft.com/en-us/library/ms748250.aspx
like image 613
Stefan Barthel Avatar asked Jan 10 '12 14:01

Stefan Barthel


People also ask

What is a markup extension?

Markup extensions are a XAML technique for getting a value that is neither a primitive nor a specific XAML type. Generally, for attribute usage, markup extensions are identified by being covered by a start and end brace. For example: {x:Static local:AppConstants. DefaultName} .

What is markup extension in WPF?

The most common markup extensions used in WPF programming are those that support resource references ( StaticResource and DynamicResource ), and those that support data binding ( Binding ). StaticResource provides a value for a property by substituting the value of an already defined resource.

What is markup extension in xamarin forms?

On the programmatic level, a XAML markup extension is a class that implements the IMarkupExtension or IMarkupExtension<T> interface. You can explore the source code of the standard markup extensions described below in the MarkupExtensions directory of the Xamarin. Forms GitHub repository.


1 Answers

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.

like image 96
Samuel Slade Avatar answered Oct 12 '22 06:10

Samuel Slade