Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a text in XAML which contains double and single quotation marks?

Tags:

wpf

xaml

In my XAML file I want to display this text which contains double and single quotation marks:

You shouldn't choose "Copy if New".

None of these work:

<TextBlock Text="You shouldn't choose "Copy if New":"/> <TextBlock Text="You shouldn't choose ""Copy if New"":"/> <TextBlock Text="You shouldn't choose \"Copy if New\":"/> <TextBlock Text='You shouldn't choose \"Copy if New\":'/> <TextBlock Text='You shouldn\'t choose \"Copy if New\":'/> 

I give up, can I do this in XAML?

like image 972
Edward Tanguay Avatar asked Jul 09 '09 11:07

Edward Tanguay


People also ask

How do you escape and in XAML?

The short answer is to use &amp; to encode an ampersand.


2 Answers

You should encode the special characters:

<TextBlock Text='You shouldn&apos;t choose &quot;Copy if New&quot;:'/> 
  • &apos; for '
  • &quot; for "
like image 85
Julien Poulin Avatar answered Nov 08 '22 18:11

Julien Poulin


There are defined XML escapes &amp; &quot; for " and &amp; &apos; for ' -- if the XML handling in XAML doesn't interpret those properly, then start to worry.

like image 21
Steve Gilham Avatar answered Nov 08 '22 20:11

Steve Gilham