TextBox.FontSource Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets the font source that is applied to the TextBox for rendering content.
Assembly: System.Windows (in System.Windows.dll)
Property Value
Type: System.Windows.Documents.FontSourceThe font source used to render content in the text box. The default is null.
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | 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 MyStackPanel.Children.Add(MyTextBox); }
Show: