Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FontSizeConverter Class

Converts font size values to and from other type representations.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public class FontSizeConverter : TypeConverter
public class FontSizeConverter extends TypeConverter
public class FontSizeConverter extends TypeConverter
<FontSizeConverter .../>

The FontSizeConverter object supports conversion to and from the following types: include String, Int32, Single, and Double.

This example shows how to create an instance of FontSizeConverter and use it to change a font size.

The example defines a custom method called changeSize that converts the contents of a ListBoxItem, as defined in a separate Extensible Application Markup Language (XAML) file, to an instance of Double, and later into a String. This method passes the ListBoxItem to a FontSizeConverter object, which converts the Content of a ListBoxItem to an instance of Double. This value is then passed back as the value of the FontSize property of the TextBlock element.

This example also defines a second custom method that is called changeFamily. This method converts the Content of the ListBoxItem to a String, and then passes that value to the FontFamily property of the TextBlock element.

This example does not run. For the complete sample, see Instantiating and Using a FontSizeConverter Object Sample.

public void changeSize(object sender, SelectionChangedEventArgs args)
    ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
    FontSizeConverter myFontSizeConverter = new FontSizeConverter();
    text1.FontSize = (Double)myFontSizeConverter.ConvertFromString(li.Content.ToString());

public void changeFamily(object sender, SelectionChangedEventArgs args)
    ListBoxItem li2 = ((sender as ListBox).SelectedItem as ListBoxItem);
    text1.FontFamily = new System.Windows.Media.FontFamily(li2.Content.ToString());


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
© 2018 Microsoft