Wednesday, March 13, 2019

UWP Tip #26 - Playing on the Uno Platform Playground

Have you heard of the Uno Platform project? Uno enables UWP developers to truly create universal C# applications with UWP XAML. Reuse your views, view models and supporting code across Windows 10, iOS, Android and the web (via WebAssembly).

Get started by visiting the Uno web site, read some how-to articles on their blog, and check out the source code on GitHub. Then download Visual Studio extension installer (.VSIX) from their latest GitHub release, and do a File-->New Project in Visual Studio.

But this is a post for next time. Today, we're going to take a look at how you can try Uno on any computer, regardless of what tools or extensions are installed. Let's try the Uno Platform Playground.

In any modern web browser, simply go to Here is the screen that will greet you.

You get a neat little editor in the browser complete with XAML Editor, another editor to create JSON sample data for your page's data context, and a live preview pane that creates the page via WebAssembly. The left side has what appears to be a toolbox, but is actually a series of links for viewing the sample/starter code for each control, along with a handful of more extensive samples. At the top, you can click run to render your page or keep AutoRun checked to get a live preview as you modify the XAML and data. The Save Snippet link in the upper-right corner will copy the XAML snippet to your clipboard.

Add a little XAML of your own and maybe a line of data in the JSON, and watch the live preview render the output with your updates.

I added a horizontal StackPanel containing a HyperlinkButton and two Button elements.

<StackPanel Orientation="Horizontal" Spacing="10">
    <HyperlinkButton Content="Windows Dev Center"
    <Button Content="Click Me"/>
    <Button Content="Click Me Too"/>

Let's have a look at the "Cards" sample.

This sample uses a ListView with a DataTemplate to create the look and feel of cards. The ListView's ItemsSource is set to the JSON in the Data Context editor. You can edit any of this and watch the preview pane reload with your changes. Remember to click Run if you have disabled AutoRun.

The Playground is a great place to play with the tools and copy some of your "play code" into a real live project in Visual Studio. Curious about how the Playground was built? That source code is also available. View it here.

Go play today, and leverage your UWP skills across every platform! Happy coding and #uwpeverywhere! Tags: ,,

Sunday, February 10, 2019

UWP Tip #25 - Windows Community Toolkit - Using the TabView Control

Here at UWP Tips, I have walked through how to use many of the controls, services and helpers available in the Windows Community Toolkit. The toolkit reached the v5 milestone at the end of October and added a number of new features and enhancements. One of the new controls is the TabView XAML control. Today, we'll examine the control and create a quick sample UWP Page.

Let's start by viewing the control in the handy toolkit sample app that you can install from the Microsoft Store. I added a yellow border to identify the bounds of the control itself.

You can see that the control has header and footer regions, a row of tabs with the ability to add tabs using the + icon, and a settings button to enable user configuration of the tab behavior. Based on the settings exposed on the right through the sample app, you can also see that it is easy to change the tab width settings, add close tab buttons and provide drag-and-drop behavior to rearrange tabs.

Let's crate a new UWP project and get our hands on some XAML. Once your project is created, add the Microsoft.Toolkit.Uwp.UI.Controls v5.0 (or later) NuGet package. I have also added MVVMLight for some quick MVVM support.

Let's keep the XAML really simple for our first test run with the TabView. Here is the markup for a TabView with a header, footer and four tabs.

                 <TextBlock Text="Top of the World!"/>
             <controls:TabViewItem Header="First Tab">
                 <TextBlock Text="First tab Contents!"/>
             <controls:TabViewItem Header="Tab 2">
                 <TextBlock Text="Tab 2 contents!"/>
             <controls:TabViewItem Header="3rd Tab">
                 <TextBlock Text="3rd tab contents!"/>
             <controls:TabViewItem Header="Last Tab">
                 <TextBlock Text="Last tab contents!"/>
                 <TextBlock Text="The End"/>

If you want to see an example with a little more complexity, check out the XAML tab for the TabView in the toolkit sample app. Here is what our XAML renders at runtime.

It doesn't look to bad for a view lines of XAML, if you ask me. We are all ready to plug in four tabs full of great content, and we support Windows theming out of the box. Hover over the tabs and see how they have a nice, fluent look and feel also. Very cool!

Before we wrap up this simple example, let's clean things up with some margins on our TextBlock elements and copy some XAML from the sample app to get that cool Settings icon at the end of our tab row. Here is that markup:

   <Button Width="48"
       Style="{StaticResource ButtonRevealStyle}">
     <Viewbox MaxWidth="16" MaxHeight="16">
       <SymbolIcon Symbol="Setting"/>

Place this between your last TabViewItem and the TabView.Footer element. This is the what our Page looks like now.

Now our text has a little breathing room, and our tabs have a settings button. (It's up to you to add the settings, of course.)

That's it for our quick tour of the TabView. There's loads more to explore in this control. I recommend starting with the MS Docs page for the control, and then head over to the GitHub repo to check out the source.

Happy coding!

Saturday, January 19, 2019

UWP Tip #24 - Get Started Building Windows UI XAML with XAML Studio

XAML Studio was recently made available as a Microsoft Garage project without much fanfare. You may have heard of it if you're a regular viewer of the On .NET show on Channel 9. XAML Studio's creator, Michael Hawker, joined Jeremy Likness to discuss the project last week.

What Is XAML Studio

XAML Studio aims to provide Windows UI developers with a quick way to create and prototype XAML markup for Windows. If you miss old lightweight XAML editors like XamlPad, you should install XAML Studio today. These are a few of the features already available in this early version of the tool.
  • Live Preview
  • Live Binding
  • Binding Debugging
  • Data Context Editor
  • Auto-Save (with Restore)
  • IntelliSense
  • Documentation Toolbox with Links to MS Docs
  • Alignment Guides
  • Namespace Helpers

Getting Started

You can search for XAML Studio in the Microsoft Store and install it from there or use this handy link. When you open the app for the first time, you'll be greeted by a Welcome screen like this.

XAML Editor

If you have an existing WinUI XAML file you would like to try, you can use the Open File link. Let's get started today by clicking the New File link to create and start editing your first XAML file.

The new XAML file is a Windows Page containing a Grid with a 2-line TextBlock. Let's start slow and the Run text of each line a little bit to read "Get Started with XAML Studio on UWP Tips" and "Check out the live preview.". You'll notice that the live preview is exactly that... live. The text in the preview will refresh as you change it in the editor.

IntelliSense and Live Preview

Let's test out the IntelliSense by adding a couple more controls to the page. We'll switch out the Grid for a StackPanel with the default vertical orientation and add a Button and another TextBlock.


The IntelliSense is quite nice, but I think the default Live Preview refresh interval is a little fast. The bright pink error messages about invalid markup are distracting while working in the editor. You can either disable auto-compilation or edit the interval in the app's settings. The default interval is to compile after 0.8 seconds of inactivity in the editor. I updated mine to 2 seconds.

You should take some time to explore all of the XAML Studio settings as you're getting familiar with the app.

Documentation Toolbox

Something else you should explore is the Documentation Toolbox in the left panel.

Here you can view all of the WinUI XAML controls available to the editor, complete with little info icons that link to the Microsoft Docs online documentation. The control name and namespace appear in the list for each item. If you have controls that you frequently use, you can add them to your favorites so they always appear at the top of the list.

Data Binding

Want to add some dynamic content to your page without coding up your model, view model or connecting to a live data source? You can create a mocked up data source with some JSON data in the Data Source pane on the left.

For this prototype, I grabbed some sample JSON data from one of Adobe's sites. This data contains an array of donuts, each with its own array of batters and toppings and some other properties. It's a handy bit of small, yet semi-complex data.

From the Data Source pane, you can save your JSON, open other JSON data files, or connect to a Remote Data Context. Using a remote data context is as simple as entering a REST Url that returns valid JSON data. The returned data will populate your Data Source window and can be saved for later use.

Here is my XAML markup from the screenshot above with bindings added for the donut JSON data.

<StackPanel Padding="40" DataContext="{Binding}">
     <TextBlock Margin="8">
         <Run FontSize="24" Foreground="#FFFC5185">Get Started with XAML Studio on UWP Tips</Run><LineBreak/>
         <Run>Check out the live preview.</Run>
    <Button Content="I Do Nothing" Margin="8"/>

    <ListView ItemsSource="{Binding}">
                 <StackPanel Orientation="Horizontal">
                     <TextBlock Text="{Binding Path=id}" Margin="4"/>
                     <TextBlock Text="{Binding Path=type}" Margin="4"/>
                     <TextBlock Text="{Binding Path=name}" Margin="4"/>
                     <TextBlock Text="{Binding Path=rating}" Margin="4"/>

These binding expressions are all valid except for one. Want to quickly know which of your bindings is invalid? Switch to the Debug Bindings pane and turn on the Debug toggle.

After debug is enabled on bindings, a list of the binding expressions will display in the pane with a 'Successful' or 'NotBound' status next to the binding target. A timestamp of the last bound time will display with any bindings that have been successful. In addition, the binding expressions in the code editor will be highlighted to indicate their status, making it easier to navigate to the failed bindings.

In my case, I tried to bind to a "rating" property, which does not exist on the donut array items in the JSON data.

Next Steps

That's all we're going to explore in this intro to XAML Studio. Next time we'll dive a little deeper into remote bindings, bind some more complex controls, and see how easily we can take our prototype XAML over to a real UWP application in Visual Studio.

Go check out XAML Studio today and be sure to provide feedback to Michael on Twitter!

Happy XAMLing!

Friday, November 2, 2018

Windows Developer Resource Roundup - November 2018 Edition

I typically leave the link blogging over on the Morning Dew, but I thought my readers here might appreciate a post with a rundown of useful resources for Windows developers.

GitHub Repositories

We'll start off with some GitHub repos that I have starred. The organizations behind each repo are listed in parentheses.

Windows UI Library (Microsoft) - These are the Microsoft UWP XAML controls/styles/materials created for backward compatibility across Windows 10 versions back to the Anniversary Update. As new features are added, you can immediately make them available to your apps across all of these versions of Windows.

Windows Community Toolkit (Windows Community Toolkit) - If you follow my blog, you're very familiar with this toolkit. Formerly known as the UWP Community Toolkit, it now provides a phenomenal set of controls, helpers and services for all Windows developers.

Windows Template Studio (Microsoft) - I've also blogged about this extension on several occasions. WTS provides templates for Visual Studio and a wizard to bootstrap your UWP app with a great foundation built on popular tools and good patterns & practices.

Rapid XAML Toolkit (Microsoft) - This toolkit is a newer community effort spearheaded by Matt Lacey. It is still in preview and aims to accelerate app development for all XAML developers - UWP, WPF, and Xamarin.Forms. I blogged about the toolkit a couple of weeks ago if you would like to learn more.

Fluent XAML Theme Editor (Microsoft) - This is the source code for the Fluent XAML Theme Editor app, now available in the Windows Store. Build your own Fluent theme with light and dark support and use it in your own apps. The app requires Windows SDK version 17763 or higher.

Prism (Prism Library) - Prism is the ultimate framework for XAML developers, with support for WPF, UWP, and Xamarin.Forms. Make your apps more maintainable and testable with simple and robust MVVM, DI, commands and other patterns & tools.

MVVM Light Toolkit (Laurent Bugnion) - MVVM Light offers an alternative to the MVVM framework provided in Prism. It supports UWP, WPF and Xamarin Forms/iOS/Android. This was the first MVVM library I used and it's still a favorite when putting together sample apps.


A good framework or toolkit needs great documentation, right? Get the docs here, or contribute to them with your own expertise!

Universal Windows Platform Docs - The Microsoft Docs landing page for all UWP documentation. There are resources to get started, design, develop and publish your apps, as well as a full API reference.

Windows Community Toolkit Docs - The Microsoft Docs home for Windows Community Toolkit docs. Get help with controls or helpers in the toolkit, use get a reference for APIs or contribute to the docs yourself.

Prism Documentation - The official docs for the Prism Library. There are some general guides and sections specific to WPF and Xamarin.Forms.

MVVM Light Documentation - The MVVM Light docs have some samples, walkthroughs, and a link to a fundamentals course on Pluralsight.


Keep up with the latest news.

Windows Developer Blog - The official Microsoft blog for the Windows Dev team. Subscribe for updates on SDKs, toolkits, Windows 10 releases and more.

Windows 10 Blog - This blog is the place to get announcements of new Windows features, upcoming events, and releases of new Windows 10 builds (final and Insiders).

The Visual Studio Blog - If you're a Windows developer, there's a pretty good chance you use Visual Studio. Keep up with the latest VS news here.

XAML Brewer - Diederik Krols has some great UWP tutorials on his blog, most recently about improving accessibility in a control.

Official Microsoft Sites

Windows Dev Center - The Microsoft hub for Windows developers. This site has links to all the resources Windows developers need today. Get to docs, tools, SDKs, events, design resources, and register to sell your apps on the Store through the Partner Center dashboard.

Visual Studio App Center - Sign up for the App Center can get continuous integration against your app's repo, test it on actual devices with automation, and deploy to beta testers and production users. You can also get crash reports and analytics with a few API hooks in your app.

Microsoft Design - Get information about the Fluent Design System and start designing and developing your apps with Fluent Design.

Windows Community Toolkit Sample App - Get the sample app to demo the components inside the Windows Community Toolkit.

Visual Studio Marketplace - Windows Template Studio - Download and install WTS from the VS Marketplace. Love the tool? Leave a review!

Other Sites

Prism LIbrary - Prism's home page. It's got links to their docs, learning resources and their Slack channel.

MVVM Light Toolkit - The MVVM Light homepage.

Stack Overflow - Questions tagged "uwp" on Stack Overflow.

@windowsdev - Follow the Windows Developer team on Twitter.

#ifdef WINDOWS - Join Nikola Metulev, Sr. Program Manager for Windows Dev, for a regular video series on Channel 9 where he interviews engineers on the Windows platform.

That's all I have for this first edition. If you have suggestions for future posts, please leave a comment or ping me on Twitter. I plan on posting these semi-annually, but if I get enough suggestions, I may have to create a second edition sooner. Thanks!

Saturday, October 13, 2018

UWP Tips Early Look - Rapid XAML Toolkit (Beta)

Note: The Rapid XAML Toolkit isn't UWP-specific. You can leverage these tools for WPF and Xamarin.Forms development. XAML developers, check it out today!

In today's tip, we will have a peek at a cool project still in early beta stages, the Rapid XAML Toolkit. What is this toolkit? From their on GitHub:
These tools aim to reduce the time and effort required to get the basics working and allow you to customize the UI to meet your preferences or the specific needs of your app. We can't and don't try to create the whole app for you but we can make creating and working with XAML faster easier.
In short, the toolkit can take a set of properties from a ViewModel in your project and generate XAML controls in your corresponding View.
To give this a try, you will need to download the source and run it in an experimental instance of Visual Studio. Get the full instructions from the getting started guide here. No VSIX file is available yet to run the toolkit in VS itself. That will be coming later. Let's give it a try.
You should have completed these steps from the getting started guide:
  1. Clone or download the Rapid XAML Toolkit solution
  2. Open and build the solution
  3. Run/Debug the toolkit solution in an experimental VS instance
Now, in the newly started instance of Visual Studio, create a new UWP project.


You could also open an existing UWP project, if you have one handy. If not, add a new ViewModel, some model classes, and set up your data context, using your favorite MVVM toolkit/method. One other thing you will need to set up is in the Rapid XAML Toolkit settings in your VS options:


Select a Profile and click "Set as Active". This will control how your copied ViewModel data is prepared and converted to XAML for your view. Save your settings, return to one of your viewmodel classes and highlight some properties to be copied. Then right-click and select the Rapid XAML menu:


You can either copy the converted XAML to your clipboard or send it to your VS Toolbox to be dragged to your view(s). Next, open a view and paste those properties into the XAML editor.


For this given ViewModel data that was copied:

public string PatientName { get; private set; }

public int SSN { get; set; }

public DateTimeOffset VisitDate { get; set; }

public string VisitNotes { get; set; }

public decimal CurrentWeight { get; }

public ObservableCollection<Medication> Prescriptions { get; set; }

For reference, this is the Medication model class:

public class Medication
     public int Id { get; set; }
     public string Name { get; set; }
     public string UnitOfMeasure { get; set; }
     public double Strength { get; set; }

You will have this XAML markup pasted:
<TextBlock Text="{Binding PatientName}" />

<Slider Minimum="0" Maximum="100" x:Name="SSN" Value="{Binding SSN, Mode=TwoWay}" />

<DatePicker Date="{Binding VisitDate, Mode=TwoWay}" />

<TextBox Text="{Binding VisitNotes, Mode=TwoWay}" />

<TextBlock Text="{Binding CurrentWeight}" />

<ListView ItemsSource="{Binding Prescriptions}">
         <DataTemplate x:DataType="model:Medication">
                 <TextBlock Text="{x:Bind Id, Mode=OneWay}" />
                 <TextBlock Text="{x:Bind Name, Mode=OneWay}" />
                 <TextBlock Text="{x:Bind UnitOfMeasure, Mode=OneWay}" />
                 <TextBlock Text="{x:Bind Strength, Mode=OneWay}" />

I'll grant that it doesn't create the prettiest UI, but it is still an early beta and very little editing is required from this point to create something usable. Here is what the generated view looks like to a user:


Keep an eye on this project. I have a feeling it is going to eventually be a big time-saver for Windows devs. If you are the adventurous type, go out and download the beta source today. Have an idea to improve the toolkit? Create an issue on GitHub and start a discussion.

Happy coding! Tags: ,,