Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

How to make a static string Bold...

My Task..........

C#
TextBlock textblock = new TextBlock();
textblock.Text = "Display Metrics:";
textblock.FontWeight = FontWeights.Bold;
String str=textblock.Text;
mystackpanel.Children.Add(textblock);


Now textblock has a "Display Metrics" text which is bold, how to copy this bold text to a String str.
Posted
Updated 9-Sep-10 1:57am

The String class in .NET holds a sequence of Unicode characters. It does not hold any formatting information.

Nick
 
Share this answer
 
Comments
Kunal Chowdhury «IN» 9-Sep-10 8:01am    
Posted by amjad syed on 30 Jan '10:

Hi Nick, Thanks for your answer. so any other alternate for this.
You could save the values in an XML format. You could save Text to an element and you could save FontWeight to an attribute. Get them both from textblock.

Also, since TextBlocks can contain text with a variety of formatting, you might want to look into TextBlock.Inlines, which will help get the formatting of TextBlocks created like so:
XML
<TextBlock Name="tb1">
    This has some <Bold>bold</Bold> text.
</TextBlock>
 
Share this answer
 
Comments
Kunal Chowdhury «IN» 9-Sep-10 8:04am    
Posted by amjad syed on 1 Feb '10:

I am not allowed to use textblock...... i can use richtextbox, but as per my knowledge there is control called Richtetxblock in Silverlight, if have any dll for this plsease forward me. please feel free to tell me the alternate solution.
AspDotNetDev 9-Sep-10 22:24pm    
I don't see any comments by amjad that say that.
You could try using a rich text box to display text.

This way you can copy the rich text format and then paste in another rich text box.
 
Share this answer
 
RichTextBox here.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900