Showing posts with label winui. Show all posts
Showing posts with label winui. Show all posts

Friday, April 16, 2021

Announcing Learn WinUI 3.0 from Packt Publishing and a Contest

I'm thrilled to announce that my new book from Packt Publishing, Learn WinUI 3.0, was published in late March. You can buy your eBook or print copy today from Amazon or Packt's web site.


Windows UI (WinUI) 3 is Microsoft's next generation library for creating Windows applications with Fluent Design. WinUI 3 was released in March with Project Reunion 0.5 and is fully supported for building Win32 applications. Learn more about WinUI and Project Reunion on Microsoft Docs here.

I would like to thank Nick Randolph, who was the technical reviewer for the book. His feedback on the book's chapters and sample code were instrumental in delivering a great resource for Windows developers. I was lucky to have him involved in this project. If you aren't already following Nick's blog, go check it out now. He has been posting some great WinUI, Reunion, and Uno Platform content in recent weeks.

If you would like to win a print copy of Learn WinUI 3.0, read on. I am going to give away four copies of the book to readers of four of my blogs:

Leave a comment on this post on any of these blogs with the name of your favorite Windows or .NET development blogger. I will pick a random comment from each blog to select the four book winners. You can comment on each blog if you like, but please only comment once on each post. Comment moderation is enabled on all the blogs, so it could take a little time for your comment to appear. Make sure you sign up with a valid email address when leaving a comment. The contest closes at 11:59PM EDT on May 14th, 2021. I will ship books to winners worldwide. Please allow some time to receive the book if you are outside of the U.S.

Good luck and I hope you all enjoy my book! If you already have a copy, win one, or buy one, please leave honest ratings and reviews on Amazon. Thanks!

Monday, February 10, 2020

I am Writing a Book - Learn WinUI 3.0

Hello UWP developers!

I wanted to provide an update on this UWP Tips blog. Most of my focus this year is going to be on my new WinUI side project. I am writing a book for Packt Publishing titled Learn WinUI 3.0. The book is due out this fall. That will hopefully coincide with a final or near-final release of WinUI 3.0.

As I am working on the book, I plan to blog about my experience with WinUI 3.0 through its preview and beta stages this year. If you would like to follow along, I encourage you to follow my WinUI Tips blog. I will occasionally cross-post or create summary blog posts here to catch up with my UWP Tips followers. Your best bet to stay informed is to subscribe to both blogs (and WPF Tips, while you're at it).

If you have any suggestions for the book or things you would like to learn more about, don't hesitate to drop me a line on Twitter or LinkedIn.

Thanks for reading!

Alvin

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.



Settings

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>
     </TextBlock>
    <Button Content="I Do Nothing" Margin="8"/>

    <ListView ItemsSource="{Binding}">
         <ListView.ItemTemplate>
             <DataTemplate>
                 <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"/>
                 </StackPanel>
             </DataTemplate>
         </ListView.ItemTemplate>
     </ListView>
</StackPanel>

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, July 27, 2018

UWP App Tips Announcement - Windows UI LIbrary (WinUI)

Big news for Windows developers this week!

On Monday, the Windows Developer team announced the preview release of the Windows UI Library. Windows UI Library, or WinUI, is a set of NuGet packages which contain UWP XAML controls and other features which can be used across different versions of Windows 10. Many of these will be compatible with release from 1607 to the latest Insiders Fast Ring builds.

Windows developers will no longer need to wait for their users to adopt the latest Windows 10 release in order to provide some of the rich features provided by these packages, like Fluent controls.

WinUI preview currently consists of two NuGet packages:

  • Microsoft.UI.Xaml - Contains new and updated XAML controls for UWP applications.
  • Microsoft.UI.Xaml.Core.Direct - Provides access to XamlDirect APIs on versions of Windows 10 that do not yet support these APIs.

Want to get started with WinUI? Here's a quick step-by-step guide to creating a project, adding the NuGet packages, and adding a couple of the new XAML controls to your main Window. Want to add WinUI to an existing UWP project? As long as your project's Minimum version is at least 14393 and Target version is 17134 or later, you can follow the same steps to add the NuGet packages.

First, create your project in Visual Studio 2017 (VS 2015 is not supported).

WinUI01

Next, open the NuGet package management window for your project. Select Browse, and search for Microsoft.UI.Xaml. Be sure to select the "Include prerelease" checkbox next to the search field or you will see no results.

WinUI02

Add the packages you want to use. After adding Microsoft.UI.Xaml, a readme file will open advising you to add the following snippet to your project's App.xaml. Be sure you do this immediately after installing the package.

<Application.Resources>
     <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</Application.Resources>

Now you can close your NuGet Package Manager and the readme.txt and App.xaml files. Let's add a couple of new and updated controls to MainPage.xaml. Start by adding a reference to your Page:

xmlns:winUiControls="using:Microsoft.UI.Xaml.Controls"

I've added a few controls to my Page, a TwoPaneView containing a SplitButton in Pane1 and a PersonPicture in Pane2.

<winUiControls:TwoPaneView>
     <winUiControls:TwoPaneView.Pane1>
         <Grid>
             <winUiControls:SplitButton Content="Click or Select" Margin="12"/>
         </Grid>
     </winUiControls:TwoPaneView.Pane1>
     <winUiControls:TwoPaneView.Pane2>
         <Grid>
             <winUiControls:PersonPicture/>
         </Grid>
     </winUiControls:TwoPaneView.Pane2>
</winUiControls:TwoPaneView>

The result is exactly what you would expect for this snippet.

WinUI03

So, what controls are included in the Microsoft.UI.Xaml package? If you open Object Browser, you will currently find a huge list classes under the Microsoft.UI.Xaml.Controls namespace. A few of the new and updated controls include:

  • ColorPicker
  • DropDownButton
  • SplitButton
  • LayoutPanel
  • MenuBar
  • NavigationView
  • ParallaxView
  • RatingControl
  • PersonPicture
  • Repeater
  • Scroller
  • SwipeItem
  • TreeView
  • TwoPaneView

Lots to love for sure. Documentation of the classes in this namespace can be found here, although much of it is currently limited and only labeled as prerelease.

Ready to play? Go check out the Getting Started article on MS Docs and the XAML Controls Gallery code on GitHub! Remember this is currently prerelease code and may undergo some change before it goes RTM.


Happy coding!