Click here to Skip to main content
14,297,827 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi Guys,

How to make a static string Bold...

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

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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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

Nick
   
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.
Rate this:
Please Sign up or sign in to vote.

Solution 3

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:
<TextBlock Name="tb1">
    This has some <Bold>bold</Bold> text.
</TextBlock>
   
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.
Rate this:
Please Sign up or sign in to vote.

Solution 4

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 6

RichTextBox here.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100