Converts font size values to and from other type representations.
Namespace:
System.Windows
Assembly:
PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Visual Basic (Declaration)
Public Class FontSizeConverter _
Inherits TypeConverter
Dim instance As FontSizeConverter
public class FontSizeConverter : TypeConverter
public ref class FontSizeConverter : public TypeConverter
public class FontSizeConverter extends TypeConverter
XAML Object Element Usage
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 Using the FontSizeConverter Class Sample.
Private Sub changeSize(ByVal sender As Object, ByVal args As SelectionChangedEventArgs)
Dim li As ListBoxItem = CType(CType(sender, ListBox).SelectedItem, ListBoxItem)
Dim myFontSizeConverter As System.Windows.FontSizeConverter = New System.Windows.FontSizeConverter()
text1.FontSize = CType(myFontSizeConverter.ConvertFromString(li.Content.ToString()), Double)
End Sub
Private Sub changeFamily(ByVal sender As Object, ByVal args As SelectionChangedEventArgs)
Dim li2 As ListBoxItem = CType(CType(sender, ListBox).SelectedItem, ListBoxItem)
text1.FontFamily = New System.Windows.Media.FontFamily(li2.Content.ToString())
End Sub
private 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());
}
private void changeFamily(object sender, SelectionChangedEventArgs args)
{
ListBoxItem li2 = ((sender as ListBox).SelectedItem as ListBoxItem);
text1.FontFamily = new System.Windows.Media.FontFamily(li2.Content.ToString());
}
System..::.Object
System.ComponentModel..::.TypeConverter
System.Windows..::.FontSizeConverter
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 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0
Reference