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.
 
Back
Top