Windows 10 Universal Windows Platform – Slide Player

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.

10-home

Step 2

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

10-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 a Name and select a Location to save to before selecting Ok to create the Project.

10-new-project

Step 4

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

10-project-add-new-item

Step 5

From the Add New Item window select Visual C# from Installed 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

10-add-new-item-library

Step 6

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

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media.Imaging;

public class Library
{
    public delegate void PlayingEvent(BitmapImage image, int index);
    public event PlayingEvent Playing;
    public delegate void StoppedEvent();
    public event StoppedEvent Stopped;

    private List<BitmapImage> items = new List<BitmapImage>();
    private int index = 0;
    private bool paused = false;

    public bool IsPlaying { get; set; }
    public int Speed { get; set; }
    public int Position { get; set; }

    public void Go(ref Image display, string value, KeyRoutedEventArgs args)
    {
        if (args.Key == Windows.System.VirtualKey.Enter)
        {
            try
            {
                display.Source = new BitmapImage(new Uri(value));
            }
            catch
            {

            }
        }
    }

    public double Add(string value)
    {
        items.Add(new BitmapImage(new Uri(value)));
        return items.Count - 1;
    }

    public double Remove(int index)
    {
        if (index >= 0 && index < items.Count)
        {
            items.RemoveAt(index);
        }
        return items.Count - 1;
    }

    public async void Play()
    {
        if (items.Any() && (!paused || !IsPlaying))
        {
            IsPlaying = true;
            paused = false;
            while (IsPlaying)
            {
                if (items.Count > 0)
                {
                    if (index < items.Count)
                    {

                        Playing(items[index], index);
                        index += 1;
                    }
                    else
                    {
                        this.Stop();
                    }
                }
                await Task.Delay(Speed);
            }
        }
    }

    public void Pause()
    {
        if (items.Any() && IsPlaying)
        {
            paused = true;
            IsPlaying = false;
        }
    }

    public void Stop()
    {
        if (items.Any())
        {
            index = 0;
            paused = false;
            IsPlaying = false;
            Stopped();
        }
    }
}

It should then appear as such:

10-library-slideplayer

Step 7

From the Solution Explorer select MainPage.xaml

10-mainpage

Step 8

Select from the Menu, View then Designer

10-designer

Step 9

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

<Page.BottomAppBar>
	<AppBar IsOpen="True" IsSticky="True">
		<StackPanel Orientation="Horizontal">
			<AppBarButton Icon="Add" Label="Add" Click="Add_Click"/>
			<AppBarButton Icon="Remove" Label="Remove" Click="Remove_Click"/>
			<AppBarButton Name="Play" Icon="Play" Label="Play" Click="Play_Click"/>
			<AppBarButton Icon="Stop" Label="Stop" Click="Stop_Click"/>
		</StackPanel>
	</AppBar>
</Page.BottomAppBar>

While still in the XAML View below <Grid Background=”{ThemeResource ApplicationPageBackgroundThemeBrush}”>enter the following XAML:

<Grid>
	<Grid.RowDefinitions>
		<RowDefinition Height="Auto"/>
		<RowDefinition Height="Auto"/>
		<RowDefinition Height="*"/>
	</Grid.RowDefinitions>
	<TextBox Grid.Row="0" Margin="20" Name="Value" InputScope="Url" KeyDown="Go_KeyDown"/>
	<Grid Grid.Row="1" Margin="5">
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*"/>
			<ColumnDefinition Width="120"/>
		</Grid.ColumnDefinitions>
		<Slider Grid.Column="0" Padding="5" Minimum="0" Name="Position" ValueChanged="Position_ValueChanged"/>
		<Slider Grid.Column="2" Padding="5" Minimum="100" Maximum="5000" Value="4000" Name="Speed" ValueChanged="Speed_ValueChanged"/>
	</Grid>
	<Image Grid.Row="2" Margin="75" Name="Display"/>
</Grid>

It should appear as such:

10-xaml-slideplayer

Step 10

Select from the Menu, View then Code

10-code

Step 11

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

public Library Library = new Library();

protected override void OnNavigatedTo(NavigationEventArgs e)
{
	Library.Speed = (int)Speed.Value;
	Library.Playing += (Windows.UI.Xaml.Media.Imaging.BitmapImage image, int index) =>
	{
		Display.Source = image;
		Position.Value = index;
	};
	Library.Stopped += () =>
	{
		Play.Icon = new SymbolIcon(Symbol.Play);
		Play.Label = "Play";
		Display.Source = null;
		Position.Value = 0;
	};
}

private void Add_Click(object sender, RoutedEventArgs e)
{
	Position.Maximum = Library.Add(Value.Text);
}

private void Remove_Click(object sender, RoutedEventArgs e)
{
	Position.Maximum = Library.Remove((int)Position.Value);
}

private void Play_Click(object sender, RoutedEventArgs e)
{
	if (Library.IsPlaying)
	{
		Library.Pause();
		Play.Icon = new SymbolIcon(Symbol.Play);
		Play.Label = "Play";
	}
	else
	{
		Library.Play();
		Play.Icon = new SymbolIcon(Symbol.Pause);
		Play.Label = "Pause";
	}
}

private void Stop_Click(object sender, RoutedEventArgs e)
{
	Library.Stop();
}

private void Go_KeyDown(object sender, KeyRoutedEventArgs e)
{
	Library.Go(ref Display, Value.Text, e);
}

private void Position_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
	Library.Position = (int)Position.Value;
}

private void Speed_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
	if (Speed != null)
	{
		Library.Speed = (int)Speed.Value;
	}
}

It should then appear as such:

10-code-slideplayer-new

Step 12

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

10-simulator

Step 13

Once the Simulator has started the Application should then appear

10-simulator-run-slideplayer

Step 14

After the Application has started running you can then type in the URL of any image e.g. http://dummyimage.com/300×200&text=Hello+World then press or tap enter to load this then use Add to create a slide from this, you can then use multiple images to build up a slide show which can be Played

10-simulator-ran-slideplayer

Step 15

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

10-stop

Step 16

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

10-emulator

Step 17

Once the Emulator has started the Application should then appear

10-emulator-run-slideplayer

Step 18

After the Application has started running you can then type in the URL of any image e.g. http://dummyimage.com/300×200&text=Hello+World then press or tap enter to load this then use Add to create a slide from this, you can then use multiple images to build up a slide show which can be Played

10-emulator-ran-slideplayer

Step 19

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

10-stop

Creative Commons License

Advertisements

One thought on “Windows 10 Universal Windows Platform – Slide Player

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