Reputation: 11578
How can escape html tags into a xaml code?
For example, if i want to show <b>text</b>
in an xaml content to put into a RichTextBox as following:
private void button1_Click(object sender, RoutedEventArgs e)
{
string mystring = "<b>test</b>";
MyRTB.Blocks.Add(Convert(@"<Bold>" + mystring + "</Bold>"));
}
static public Paragraph Convert(string text)
{
String formattedText = ParaHead + text + ParaTail;
Paragraph p = (Paragraph)XamlReader.Load(formattedText);
return p;
}
I tried with multiple combinations of {} and {} and etc but doesnt work, and I dont want use hexa scape if i can do it.
Thanks in advance
Upvotes: 2
Views: 946
Reputation: 887413
You just need to XML-escape it by replacing <
with <
.
The built-in SecurityElement.Escape
or WebUtility.HtmlEncode
functions will do that for you.
Upvotes: 3