wpf/c#: convert string to fontweight

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

How can I convert a string to a FontFamily?

Suto code:
String sFont = "Bold";
FontFamily ff = (FontFamily)sFont;

Thanks.
 
Sorry, I got tottaly messed up on the sample code in the first post.

it should be:
Suto code:
string sWeight = "Bold";
FontWeight fw = (FontWeight)sWeight;

Thanks.
 
Hi,

to convert a type of String to a type of FontWeight there's a class called
FontWeightConverter.
Here's the code for your example:

string sWeight = "Bold";
FontWeight fw = (FontWeight)new
FontWeightConverter().ConvertFromString(sWeight);

I hope it helps.

Regards,
Denis

moondaddy said:
Sorry, I got tottaly messed up on the sample code in the first post.

it should be:
Suto code:
string sWeight = "Bold";
FontWeight fw = (FontWeight)sWeight;

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top