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.

TextBox.FontSource Property


Gets or sets the font source that is applied to the TextBox for rendering content.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

public FontSource FontSource { get; set; }

Property Value

Type: System.Windows.Documents.FontSource
The font source used to render content in the text box. The default is null.


The value set is not a valid source.

If the FontSource property is set to null, any assigned custom font is cleared and the TextBox renders with the default font.

The following code example shows how you can set the FontSource property.

private void AddFont()
    //Set the font to Times New Roman using FontSource property.
    TextBox MyTextBox = new TextBox();
    MyTextBox.Text = "hello world";
    Uri MyUri = new Uri("times.ttf", UriKind.Relative);
    StreamResourceInfo MySRI = Application.GetResourceStream(MyUri);
    MyTextBox.FontSource = new FontSource(MySRI.Stream);
    MyTextBox.FontFamily = new FontFamily("Times New Roman");

    //Add the textbox to the stackpanel



Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

© 2017 Microsoft