How can I set default font for TextBox
?
For TextBlock
it's (taken from here):
TextBlock.FontFamilyProperty.OverrideMetadata(typeof(TextBlock),
new FrameworkPropertyMetadata(new FontFamily("Verdana")));
Trying to do the same for TextBox
:
TextBox.FontFamilyProperty.OverrideMetadata(typeof(TextBox),
new FrameworkPropertyMetadata(new FontFamily("Verdana")));
will throw:
Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll
Additional information: The type initializer for 'System.Windows.Controls.TextBox' threw an exception. PropertyMetadata is already registered for type 'TextBox'.
Here is repro:
<StackPanel>
<TextBlock Text="123123" />
<TextBox Text="123123" BorderThickness="0" Padding="-2,0,-2,0" />
</StackPanel>
Setting TextBlock
font as above in window constructor (before InitializeComponent()
) works. How to set TextBox
default font (it's Segoe by default to me)? I need a solution to set it in as "Verdana"
in one place for a whole application.
Intellisense shows: