Updating the font used throughout a #wp8 #app
Using a custom font is a nice design touch that helps a windows phone app stand out, by looking a little different. The Segoe font can be a bit boring…
So, the standard way this is done, is by adding the following into Application.Resources in App.xaml
<Style TargetType=”TextBlock”>
<Setter Property=”FontFamily” Value= “assets/fonts/whatever.ttf#whatever”/>
</Style><Style TargetType=”TextBox”>
<Setter Property=”FontFamily” Value= “assets/fonts/whatever.ttf#whatever”/>
</Style>
But, here’s another approach, using reflection, and page hooks, like used in a previous post:
https://blog.dotnetframework.org/2015/11/09/localise-datepicker-in-wp8-silverlighttoolkit-using-hooks/
So, from within CompleteInitializePhoneApplication, add the code
PhoneApplicationPage page = RootFrame.Content as PhoneApplicationPage;
FontChangeHook(page);
then, FontChangeHook method as follows;
public static void FontChangeHook(PhoneApplicationPage page)
{
LoopThroughControls(page, (ui => {
var type = ui.GetType();
var prop = type.GetProperty(“FontFamily”);
if (prop != null)
{
prop.SetValue(ui, new FontFamily(@”assets/fonts/whatever.ttf#whatever”));}
}));
}