WilliamLiu-0692 avatar image
0 Votes"
WilliamLiu-0692 asked WilliamLiu-0692 commented

How to escape characters in Xaml MarkupExtension?

I`m interesting on how to escape the special characters, e.g. &, a single left/right Parenthesis, backslash , and so on.

Here is my test code snippet. The purpose is using the converter to output the string you input on the xaml MarkupExtension code.


 public class ReturnInputConverter : MarkupExtension, IValueConverter
     public string Input { get; set; } = string.Empty;
     public override object ProvideValue(IServiceProvider serviceProvider) => this;
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => Input;
     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => Binding.DoNothing;

// MainWindow.xaml

     <CheckBox x:Name="CheckBox" />
     <TextBlock Text="{Binding ElementName=CheckBox, Path=IsChecked, Converter={escapeInXaml:ReturnInputConverter Input=input-here-for-preview}}" />

repo EscapeInXaml

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,@WilliamLiu-0692 . What function do you need to use special characters for? Is it the path of the binding content or something else? Have you seen the Use Special Characters in XAML and {} Escape sequence / markup extension?

0 Votes 0 ·

Hi Huiliu,

Im developing a regex related converter and want to pass the regex expression string through the xaml markup extension parameter. However, I didnt find a proper or consistent approach to input the regex expression in the xaml. So I write this simple test to demonstrate the character escape question.

0 Votes 0 ·

Hi,@WilliamLiu-0692 . How do you want to use regular expressions in xaml? Could you give an example? You can write regular expressions directly in text and content in xaml. For passing the regex expression string through the xaml markup extension parameter, you could check if the answer here is helpful to you.

0 Votes 0 ·
Show more comments

0 Answers