Windows 10 – Universal Windows Platform – Font Control

Step 1

Download Visual Studio Community 2015 and install it onto your computer, if it’s already downloaded and installed select Launch to start Visual Studio Community 2015 or if it has already been downloaded and installed then start the application you may also need to Enable your device for development.

2015-visual-studio

Step 2

Once Visual Studio Community 2015 has started select File, then New, then Project… from the Menu.

2015-file-new-project

Step 3

From the New Project window select Visual C# from Installed, Templates then select Blank App (Windows Universal) from the list, then type in the Name as FontControl and select a Location to save to before selecting Ok to create the Project.

2015-font-control-add-new-project

Step 4

Once done select from the Menu, Project, then Add New Item…

2015-project-add-new-item

Step 5

From the Add New Item window select Visual C# from Installed and select Code then select Code File from the list, then type in the Name as FontPicker.cs before selecting Add to add the file to the Project

2015-font-control-combobox-add

Step 6

Once in the Code View for FontPicker.cs the following should be entered:

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml.Media;

namespace FontControl
{
    public class FontPicker : ComboBox
    {
        private string[] fonts =
        {
            "Arial", "Calibri", "Cambria", "Cambria Math", "Comic Sans MS", "Courier New",
            "Ebrima", "Gadugi", "Georgia", "Javanese Text", "Leelawadee UI", "Lucida Console",
            "Malgun Gothic", "Microsoft Himalaya", "Microsoft JhengHei", "Microsoft JhengHei UI",
            "Microsoft New Tai Lue", "Microsoft PhagsPa", "Microsoft Tai Le", "Microsoft YaHei",
            "Microsoft YaHei UI", "Microsoft Yi Baiti", "Mongolian Baiti", "MV Boli", "Myanmar Text",
            "Nirmala UI", "Segoe Print", "Segoe UI", "Segoe UI Emoji", "Segoe UI Historic",
            "Segoe UI Symbol", "SimSun", "NSimSun", "Times New Roman",  "Trebuchet MS",
            "Verdana", "Webdings", "Wingdings", "Yu Gothic", "Yu Gothic UI"
        };

        public FontPicker()
        {
            this.ItemTemplate = (DataTemplate)XamlReader.Load(
            "<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +
            "<TextBlock Text=\"{Binding}\" FontFamily=\"{Binding}\"/>" +
            "</DataTemplate>");
            this.ItemsSource = fonts;
        }

        public FontFamily Selected
        {
            get { return new FontFamily((string)SelectedItem); }
        }
    }
}

It should then appear as such:

2015-font-control-combobox-code

Step 7

Then select from the Menu, Build, then Build Solution

2015-build

Step 8

From the Solution Explorer select MainPage.xaml

2015-mainpage-library

Step 9

Select from the Menu, View then Designer

2015-view-designer

Step 10

The Design View will be displayed along with the XAML View and in this below <Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”> enter the following XAML:

<Grid>
	<Grid.RowDefinitions>
		<RowDefinition Height="Auto"/>
		<RowDefinition Height="*"/>
	</Grid.RowDefinitions>
	<local:FontPicker Grid.Row="0" x:Name="Picker" SelectionChanged="Picker_SelectionChanged"
		HorizontalAlignment="Stretch"/>
	<TextBlock Grid.Row="1" Name="Display" TextWrapping="Wrap" FontSize="20" 
		HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>

It should appear as such:

2015-font-control-mainpage-xaml

Step 11

Select from the Menu, View then Code

2015-view-code

Step 12

Once in the Code View below the public MainPage() { … } the following should be entered:

private void Picker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
	Display.Text = "abcdefghijklmnopqrstuvwxyz " +
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ\n" +
	"1234567890.:,; '\"(!?) +-*/=\n\n" +
	"The quick brown fox jumps over the lazy dog";
	Display.FontFamily = Picker.Selected;
}

It should then appear as such:

2015-font-control-mainpage-code

Step 13

That completes the Universal Windows Application so Save the Project then select the Debug and Simulator option to run the Application

2015-simulator

Step 14

Once the Simulator has started the Application should then appear

2015-font-control-simulator-run

Step 15

After the Application has started running you can select a Font from the list to see a preview of it in the Application

2015-font-control-simulator-ran

Step 16

Another option is to run as a Windows 10 Mobile application, select Debug and select Emulator 10.0.10586.0 WVGA 4 inch 512MB option to run the Application

2015-emulator

Step 17

Once the Emulator has started the Application should then appear

2015-font-control-emulator-run

Step 18

After the Application has started running you can select a Font from the list to see a preview of it in the Application

2015-font-control-emulator-ran

Step 19

To Exit the application select Stop Debugging in Visual Studio Community 2015

2015-stop

Creative Commons License

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s