Windows 10 – Universal Windows Platform – Digital 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 DigitalControl and select a Location to save to before selecting Ok to create the Project.

2015-digital-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 XAML then select User Control from the list, then type in the Name as Digital.xaml before selecting Add to add the file to the Project

2015-digital-control-usercontrol-add

Step 6

The Design View will be displayed along with the XAML View and in this below <Grid> enter the following XAML:

<Viewbox>
	<Grid Width="86" Height="188">
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto"/>
			<ColumnDefinition Width="*"/>
			<ColumnDefinition Width="Auto"/>
		</Grid.ColumnDefinitions>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
			<RowDefinition Height="Auto"/>
		</Grid.RowDefinitions>
		<Path Name="a" Grid.Row="0" Grid.ColumnSpan="3" Margin="8,0,8,0" 
			Data="M 6,0 64,0, 70,6 60,16 10,16 0,6 z" 
			Fill="{ThemeResource SystemControlBackgroundAccentBrush}"/>
		<Ellipse Name="h" Grid.Row="1" Grid.Column="1" Height="16" Width="16" 
			Fill="{ThemeResource SystemControlBackgroundAccentBrush}"/>
		<Path Name="f" Grid.Row="1" Grid.Column="0" Data="M 6,0 16,10 16,60 6,70 0,64 0,6 z"
			Fill="{ThemeResource SystemControlBackgroundAccentBrush}"/>
		<Path Name="b" Grid.Row="1" Grid.Column="3" Data="M 0,10 10,0 16,8 16,64 10,70 0,60 0,10 0,16 z"
			Fill="{ThemeResource SystemControlBackgroundAccentBrush}"/>
		<Path Name="g" Grid.Row="2" Grid.ColumnSpan="3" Margin="8,0,8,0" Data="M 8,0 60,0,68,8 60,16 8,16 0,8 z"
			Fill="{ThemeResource SystemControlBackgroundAccentBrush}"/>
		<Path Name="e" Grid.Row="3" Grid.Column="0"  Data="M 6,0 16,10 16,60 6,70 0,64 0,6 z"
			Fill="{ThemeResource SystemControlBackgroundAccentBrush}"/>
		<Path Name="c" Grid.Row="3" Grid.Column="3" Data="M 0,10 10,0 16,8 16,64 10,70 0,60 0,10 0,16 z"
			Fill="{ThemeResource SystemControlBackgroundAccentBrush}"/>
		<Ellipse Name="i" Grid.Row="3" Grid.Column="1" Height="16" Width="16" 
			Fill="{ThemeResource SystemControlBackgroundAccentBrush}"/>
		<Path Name="d" Grid.Row="4" Grid.ColumnSpan="3" Margin="8,0,8,0" Data="M 10,0 60,0 70,10 64,16 6,16 0,10 z"
			Fill="{ThemeResource SystemControlBackgroundAccentBrush}"/>
	</Grid>
</Viewbox>

It should appear as such:

2015-digital-control-usercontrol-xaml

Step 7

Select from the Menu, View then Code

2015-view-code

Step 8

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

private int[][] table =
{
	// a, b, c, d, e, f, g
	new int[] {  1, 1, 1, 1, 1, 1, 0 }, // 0
	new int[] {  0, 1, 1, 0, 0, 0, 0 }, // 1
	new int[] {  1, 1, 0, 1, 1, 0, 1 }, // 2
	new int[] {  1, 1, 1, 1, 0, 0, 1 }, // 3
	new int[] {  0, 1, 1, 0, 0, 1, 1 }, // 4
	new int[] {  1, 0, 1, 1, 0, 1, 1 }, // 5
	new int[] {  1, 0, 1, 1, 1, 1, 1 }, // 6
	new int[] {  1, 1, 1, 0, 0, 0, 0 }, // 7
	new int[] {  1, 1, 1, 1, 1, 1, 1 }, // 8
	new int[] {  1, 1, 1, 0, 0, 1, 1 }, // 9
	new int[] {  0, 0, 0, 0, 0, 0, 0 }, // None
	new int[] {  0, 0, 0, 0, 0, 0, 0 }, // Colon
};

private int _digit;

public int Digit
{
	get { return _digit; }
	set
	{
		_digit = value;
		int[] values = table[_digit];
		a.Opacity = values[0];
		b.Opacity = values[1];
		c.Opacity = values[2];
		d.Opacity = values[3];
		e.Opacity = values[4];
		f.Opacity = values[5];
		g.Opacity = values[6];
		h.Opacity = _digit > 10 ? 1 : 0;
		i.Opacity = _digit > 10 ? 1 : 0;
	}
}

It should then appear as such:

2015-digital-control-usercontrol-code

Step 9

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

2015-project-add-new-item

Step 10

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 Library.cs before selecting Add to add the file to the Project

2015-add-new-item-library

Step 11

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

using DigitalControl;
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

public class Library
{
    private void layout(StackPanel panel)
    {
        for (int i = 0; i < 8; i++)
        {
            panel.Children.Add(new Digital()
            {
                Digit = 10,
                Height = 50,
                Margin = new Thickness(5)
            });
        }
        DispatcherTimer timer = new DispatcherTimer()
        {
            Interval = TimeSpan.FromMilliseconds(250)
        };
        timer.Tick += (object sender, object e) =>
        {
            string time = DateTime.Now.ToString("HH:mm:ss");
            for (int i = 0; i < 8; i++)
            {
                string interval = time[i].ToString();
                ((Digital)panel.Children[i]).Digit =
                interval == ":" ? 11 : int.Parse(interval);
            }
        };
        timer.Start();
    }

    public void Init(StackPanel panel)
    {
        layout(panel);
    }
}

It should then appear as such:

2015-digital-control-library

Step 12

From the Solution Explorer select MainPage.xaml

2015-mainpage-library

Step 13

Select from the Menu, View then Designer

2015-view-designer

Step 14

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

<StackPanel Name="Display" Width="300" Orientation="Horizontal" 
	HorizontalAlignment="Center" VerticalAlignment="Center"/>

It should appear as such:

2015-digital-control-mainpage-xaml

Step 15

Select from the Menu, View then Code

2015-view-code

Step 16

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

public Library Library = new Library();

Then while still in the Code View below this.InitializeComponent(); the following should be entered:

Library.Init(Display);

It should then appear as such:

2015-digital-control-mainpage-code

Step 17

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

2015-simulator

Step 18

Once the Simulator has started the Application should then appear displaying a clock using the Digital Control in the Application

2015-digital-control-simulator-run

Step 19

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

2015-stop

Step 20

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 21

Once the Emulator has started the Application should then appear displaying a clock using the Digital Control in the Application

2015-digital-control-emulator-run

Step 22

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