TextBox->FontFamily = ref new FontFamily("Arial"); Gives me Arial Narrow, not Arial

658 Views Asked by At

If I set the font for a Windows::UI::Xaml::Controls::TextBox using the following line of code:

textBox->FontFamily = ref new Windows::UI::Xaml::Media::FontFamily("Arial");

on the x86 Simulator, I get a TextBox with the Arial font. Great.

If I execute that same line of code on my Surface RT device, I get a TextBox with the Arial Narrow font. Not so great.

I checked my device to ensure the Arial font is installed. It is. On my device, I started up WORD and started composing in Arial and my characters were indeed Arial (not Arial Narrow) characters. Is there some trick I should know to get my TextBox to use the Arial font? For what its worth I tried fooling around with the FontStretch property but it had no effect at all.

2

There are 2 best solutions below

0
On

do it in xaml.

i mean.

<TextBlock FontFamily="Arial"/>

or create a resurce:

<Page.Resource>
   <Style x:Key="BasicTextStyle" TargetType="TextBlock">
       <Setter Property="FontFamily" Value="Arial"/>
   </Style>
</Page.Resource>

although the properties assigned directly to the object override the global style

0
On

One approach to explicitly force the font selection is to use the Text Object Model interface (http://msdn.microsoft.com/en-us/library/windows/desktop/bb774052(v=vs.85).aspx) to set the FontStretch property to Normal. By doing this the Arial font (not the Arial Narrow font) is guaranteed to always be used. I hope this helps!

In XAML / C++

ITextDocument^ doc = myControl->Document;
ITextCharacterFormat^ format = doc->GetDefaultCharacterFormat();
format->FontStretch = Windows::UI::Text::FontStretch::Normal;
doc->SetDefaultCharacterFormat(format);

Or in XAML / C#

ITextDocument doc = myControl.Document;
ITextCharacterFormat format = doc.GetDefaultCharacterFormat();
format.FontStretch = Windows.UI.Text.FontStretch.Normal;
doc.SetDefaultCharacterFormat(format);