Intro to Universal Windows Platform (UWP)

  1. Universal Windows Platform (UWP)
    1. UWP was introduced in Win 10 to provide a core API across devices so a single app package can run on multiple devices
    2. Device families
      1. UWP apps target one or more device families, a set of APIs, system characteristics, and behaviors that all devices in the family support
      2. Universal device family runs on all devices
      3. Child families: Desktop, Mobile, Xbox, IoT, IoT headless, HoloLens
    3. Universal input
      1. UWP apps can run on many different kinds of devices that have different forms of input, screen resolutions, DPI density, etc.
      2. Universal controls, layout panels, and tooling allow apps to optimize the UI for the device's screen resolution
      3. Common input handling allows apps to receive input through touch, pen, mouse, keyboard, or controller
    4. UWP apps made available in the Microsoft Store
      1. Similar to Mac App Store and Google Play, requiring apps to be certified for compatibility and content
      2. Apps range in price from free to $0.99 - $999.99
      3. Microsoft gets 30% of the sale price until app reaches $25K in sales, then gets 20%
      4. Currently lagging behind Mac App Store and Google Play in offerings
  2. Three ways to develop UWP apps
    1. JavaScript with HTML/CSS
      1. Use HTML/CSS for presentation and JavaScript for logic
      2. Ideal for web developers and when reusing pre-existing web content
    2. C#, Visual Basic, or C++ with XAML
      1. XAML for presentation and programming languages provide logic
      2. Very similar to WPF although uses some different classes
    3. C++ with DirectX
      1. Ideal for making graphics- or multimedia-intensive apps (games)
      2. More complex
  3. Creating a Universal Windows app with C#/XAML
    1. Use Visual Studio 2019 Community Edition (free) or Enterprise running on Windows 10
    2. Enable your machine for development (may require admin privileges)
    3. To submit your app to the Microsoft Store, create a developer account
    4. Create a C# Blank App (Universal Windows) project called HelloUniversalApp
    5. Windows project files
      1. Assets folder
        1. Contains images: small and large logo, splash screen, Microsoft Store image
      2. App.xaml and App.xaml.cs
        1. Responsible for settings or activities that affect the enire app
        2. App class inherits from Windows.UI.Xaml.Application
      3. MainPage.xaml and MainPage.xaml.cs
        1. First page the application displays to user
        2. .xaml.cs file contains the logic that interacts with the components declared in the .xaml file
        3. An app can have multiple pages which each have .xaml and .xaml.cs files
        4. MainPage class inherits from Windows.UI.Xaml.Controls.Page
      4. Package.appxmanifest
        1. XML file containing metadata about the app: name, description, tile, start page, etc.
        2. List of files app contains
        3. Lists the needed device capabilities (Internet, microphone, Music library, webcam, etc.)
    6. Add button and click handler
      1. Drop Button from Toolbox onto MainPage.xaml
      2. Create Click handler that uses SpeechSynthesis to perform Text-To-Speech (TTS)
        <Button x:Name="button" Content="Say Hello" HorizontalAlignment="Left" 
            Margin="155,244,0,0" VerticalAlignment="Top" Click="button_Click"/>
        
        private async void button_Click(object sender, RoutedEventArgs e)
        {
        	button.Content = "Hello, Universal Apps";
        
        	MediaElement mediaElement = new MediaElement();
        	var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
        	Windows.Media.SpeechSynthesis.SpeechSynthesisStream stream = await 
        		synth.SynthesizeTextToStreamAsync("Hello, Universal apps!");
        	mediaElement.SetSource(stream, stream.ContentType);
        	mediaElement.Play();
        }
        
    7. Build the project
      1. Executable (.exe in \bin\x86\Debug) is composed of CIL but cannot run stand-alone!
      2. Cannot distribute .exe to others; can only be run in Visual Studio
      3. To build deployable package: Project → Publish → Create App Packages...
        1. Requires a developer's key to sign the package
        2. Produces .appx file in bin\x64\Debug composed of files from AppPackages directory
        3. The .appx file is a zip file that contains the .exe and other support files
        4. This file is what you would normally publish to the app store or push to computers in enterprise environment (sideloading)
    8. Ctrl-F5 to run on target (local machine, remote machine, or simulator)
      1. Splash screen appears first (Assets/SplashScreen.scale-200.png)
      2. App appears in own window