How to set FontWeights to any value (Bold, UltraBold, ...) from C# Reflection?

Dnx_7
Dnx_7 used Ask the Experts™
on
Hi experts,

I have a string that contains "Bold" or "UltraBold" or something else that represents a FontWeights (in string format).
I also have an object (Type) that reprensents the "FontWeights" of a WPF control (from textblock or textbox or else)
I don't know how to set the String value to a fontweight value from reflection in C#

Any helps will be grateful,


Thanks,

Kind Regards.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

There is a class FontWeightConverter, which exposes a method ConvertFromString, which will do the convertion you need. Just keep in mind, that the method returns a type of object, so you will need to cast the result to FontWeights.

Giannis

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial