We built an application in XAML. Now I need to format the text strings.
Is it possible to bold only part of the text string. We are replacing an element's text in a XAML textblock with a text string. What would be the easiest way to make parts of the text string bold? Would I add a label? Something else in the XAML or in the C#?
Here is an example of our XAML and our code behind:
XAML
<TextBlock x:Name="PrimaryNameText" Text="Primary Member Name:"></TextBlock>
C# String
PrimaryNameText.Text = "Primary Member Name: " + reAccount.MyPerson.Prefix + " " + reAccount.MyPerson.FirstName + " " + reAccount.MyPerson.LastName;
In the example above, we more or less want to bold the part of the string "Primary Member Name: "
I know you can do a "\n" for a page break, is there a way we can do something for bolding text in the string?
Use a span inside your TextBlock.
<TextBlock>
<Span x:Name="PrimaryNameBold" FontWeight="Bold"></Span>
<Span x:Name="PrimaryNameNormal"></Span>
</TextBlock>
And in your code:
PrimaryNameBold.Text = "Primary Member Name: ";
PrimaryNameNormal.Text = reAccount.MyPerson.Prefix + " " + reAccount.MyPerson.FirstName + " " + reAccount.MyPerson.LastName;
Not an awesome solution, but this should work.
Related
I want to replace the selected text in a TextBox with another string in c# . I am using the following code but it replaces all the same texts in all the TextBox (not only my selected text). How may I solve this?
string selectedTxt = TextBox1.SelectedText;
TextBox1.Text = TextBox1.Text.Replace(selectedTxt, "<b>" + selectedTxt + "</b>");
No need to replace, just set the SelectedText property with new text. Explanation here
string selectedTxt = TextBox1.SelectedText;
TextBox1.SelectedText = "<b>" + selectedTxt + "</b>";
The following value expression for placeholder works in html type input in the table header
= Sum(CDec(Fields!TotalDueAmount.Value))
But when I change it to concatenate a string it doesn't work. I tried below both of them shows #Error
= "Total: " + Sum(CDec(Fields!TotalDueAmount.Value))
= "<b>" + First(Fields!TotalLabel.Value, "ModelData") + ": " + "</b>" + Sum(Fields!TotalDueAmount.Value, "ModelData")
You need to convert the sum back to a string to concatenate it with other strings:
= "Total: " + CStr(Sum(CDec(Fields!TotalDueAmount.Value)))
An even better option is to use a placeholder. Type "Total: " in the textbox and then right-click in the textbox after it. Select the option to create a placeholder. Set the Value to Sum(CDec(Fields!TotalDueAmount.Value)). Now you can adjust the number formatting on the placeholder independently.
If i have an image tooltip that is being populated from a database table. I am generating this html below from my server side C# code
public string GetImage()
{
return "<img class='iconSpace' title ='" + dataIssue + "' src='/Content/Images/Icons" + size + "/information_red.png' />";
}
the issue is that if the variable dataIssue has an apostrophe in it, it only shows the characters in the string up to that point.
What is the best way to show the whole string in the tooltip given the code above?
' is not special symbol for HTML, and browser shows whole string without problems, but you can have problems with following symbols " < > & they should be escaped as:
"
<
>
&
if your browser treats HTML standard incorrectly and cut the rest of the string, you can try to escape single quote with ' - this will work for all browsers
so, according HTML standard attribute values should be surrounded by " symbol, not by ', so the problem here should be solved:
dataIssue = any_kind_of_html_escape_function_here(dataIssue);
return "<img class=\"iconSpace\" title=\"" + dataIssue + "\" src=\"/Content/Images/Icons" + size + "/information_red.png\" />";
For asp.net htmlencode function is defined here: http://msdn.microsoft.com/en-us/library/w3te6wfz.aspx
Would this work for you?
string img = "<img class=\"iconSpac\" title=\"" + dataIssue + "\" " + "scr=\"/Content/Images/Icons\"" + size + "/information_red.png\" />";
You should use HttpUtility.HtmlEncode("...") for it.
http://msdn.microsoft.com/en-us/library/73z22y6h.aspx
while (reader.Read())
{
sb2.Append("<a href=" + "Doc/" + reader[1].ToString() + "
target=_blank style=text-decoration:none; color:#000;>" + reader[0].ToString() + "</a><img src=images/new1.gif> </img><hr />");
}
/* for example
i want to save image name abhi shek.jpg but these hyperlink only get abhi after space not
get anything pls solve these problem */
The reason that the attribute is cut at the space is that you don't have quotation marks around the value. What comes after the space becomes a different attribute. You should have quotation marks around the other attribute values also. If you don't have them around the style value, the color won't be part of the style.
Also, spaces in an URL is invalid, you need to encode the name.
sb2.Append("" + reader[0].ToString() + "<img src=\"images/new1.gif\"> </img><hr />");
strEmail =
"Hi All,"
+ "<br>"
+ "The User "
+ lstDataSender[0].ReturnDataset.Tables[0].Rows[0][1].ToString()
+ " has been created on "
+ DateTime.Now.ToShortDateString()
+ "."
I am writing C# code to generate an email whenever a new user has been created. I need the body of the mail in a mail format like
hi,
The user "xxx" has been created on "todaysdate".
Thanks,
yyyy
so I need to insert linebreaks and bold for some characters. How might I achieve this?
If this is a plain text email (which it looks like it is), use \r\n for new lines.
strEmail = string.Concat("Hi All,\r\n\r\nThe User",
lstDataSender[0].ReturnDataset.Tables[0].Rows[0][1].ToString(),
"has been created on ",
DateTime.Now.ToShortDateString(),
".\r\n\r\nThanks, yyyy");
Strickly speaking this should be Environment.NewLine to support different platforms, but I doubt this is a concern.
Set
yourMessage.IsBodyHtml = true
Msdn-Reference can be found here.
In order to form, you can use like below:
Response.Write("Hi,<br/><br/>The user.......");