未加星标

Desktop Applications with XAML. Part 1: UWP

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二05 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

If you are creating WPF applications, what is the path going forward? What’s the best way going forward to build modern desktop applications. Of course, one way is to use HTML and javascript (or TypeScript) like it’s done with Visual Studio Code. However, XAML and C# is still a great way building desktop applications with many fascinating options to go ahead. In this article series I explain what the options are e.g. using the Universal windows Platform (UWP) going forward, or enhancing WPF applications with new features. In the first part UWP has the focus. A later article follows where you can see how to use features from UWP within WPF.

With the article series I try to explain what the options are and how you can decide to chose your best way going forward creating desktop applications with XAML and C#.


Desktop Applications with XAML. Part 1: UWP
UWP Applications

The best option to build XAML applications for the desktop today is using the Universal Windows Platform . Windows 10 itself is using this technology to build its user interfaces. You can create XAML-based applications with C# and C++, and make use of the Windows Runtime.

New controls offer great improvements compared to WPF. Instead of using binding based on reflection, you can use compiled binding with compilation errors if bound properties cannot be found. It’s faster, as behind the scenes properties are directly set. The application is compiled to native code. This way it’s not just the binding that’s faster.

To see the available controls in action, you can install the XAML Controls Gallery app from the store. This application not only shows the controls in action, but also gives you XAML code how the control can be used, and also links to documentation and guidelines.


Desktop Applications with XAML. Part 1: UWP

UWP controls have animations built-in by default. Using WPF you need to do a lot more on your own to create an app that looks good.

Sample Business Application

A great example for a modern business application created with UWP is the Van Ardsel Inventory application. The source code is available at GibHub Microsoft Inventory Sample App .

Starting the application, already the login looks different. A big picture is shown, and you can login using Windows Hello , or using traditional username/password.


Desktop Applications with XAML. Part 1: UWP

After logging in, the application makes use of the NavigationView control with a Hamburger button which is common nowadays. The main screen shows a dashboard with a nice look customers, products, and orders.


Desktop Applications with XAML. Part 1: UWP

The application also offers an adaptive UI. As the available screen changes, the application adapts features built into XAML.


Desktop Applications with XAML. Part 1: UWP

The application offers a Master/Detail view with editable details. Changing from the read mode to the edit mode using the standard look of the TextBox control it’s difficult for the user to see the mode he’s in. This application not only offers an Edit button to change in the edit mode, but also as soon as the user clicks into a TextBox control, the edit mode is active.


Desktop Applications with XAML. Part 1: UWP

The products page looks different. All the products are shown in an adaptive grid.


Desktop Applications with XAML. Part 1: UWP

Clicking on a product, the detail page opens in a separate top-level window. With the other views, the click of the button, you can also open the display in a separate window. Yes, UWP also allows to open new windows.


Desktop Applications with XAML. Part 1: UWP

Behind the scenes, the application makes use of the MVVM pattern with the Microsoft.Extensions.DependencyInjection DI container. The view-models are created within a .NET Standard library. This way it should be possible to use the same view-models and services not only from UWP but also from WPF and Xamarin. Just the user interface needs to be re-created.

UWP Controls and Windows Runtime Versions

One issue we had using UWP controls is that the controls were related to a specific version of the Windows Runtime. Using a new control, it was necessary to wait until all users switched to the version of Windows where the control or the new features of a control are available.

With the Windows UI Library this is no longer the case. This library just requires the minimum version to be set to at least 14393, and the current version to 17134 or higher. The NuGet package has the name Microsoft.UI.Xaml and is currently available in preview.

In the book Professional C# 7 and .NET Core 2.0 , I’ve changed a WPF application using a tree-view control to UWP. At the time of the writing, the TreeView control was not available with UWP. Because of this, I’ve used a C++ TreeView sample component offered by Microsoft and used it within the application. This had the disadvantage that users compiling the sample also needed to install the C++ compiler with Visual Studio to build the TreeView control. Since Windows 10 version 1803 (10.0.17134.0), UniversalApiContract v6, Windows 10 has a TreeView control. I changed the sample code to use this control instead. This has the disadvantage that users need to have at least Windows 10 version 1803. Next I’m changing the sample again to use the control from the Windows UI Library . This way, users can work with older Windows 10 versions.

Windows Template Studio

To see what you can all do with Universal Windows apps, it’s easy to start with the Windows Template Studio . This is a Visual Studio extension that allows you to create an application step by step using a wizard.

With the first step project type , you can select the main layout of the application: using either a navigation pane or tabs , or start with a blank page where you have to do the layout on your own.


Desktop Applications with XAML. Part 1: UWP

In the second step design pattern you select the library to use. You can choose between simple code behind, or an MVVM architecture either using MVVM Basic where the MVVM classes are implemented within the application, or use a library such as MVVM Light , Caliburn.Micro , or Prism .


Desktop Applications with XAML. Part 1: UWP

The third step pages allows you to create pages where you select the pages from a large list including for example Master/Detail, DataGrid, Tabbed, Map, Camera, Ink, Chart, and many more.


Desktop Applications with XAML. Part 1: UWP

The last final step features gives you many features you can choose from, such as deep linking, Web to app link, recording user activity with the Windows timeline, create multiple views, background tasks, implement share contracts, drag and drop, add theme support, and much more.


Desktop Applications with XAML. Part 1: UWP
Summary

Starting with Windows 8, the Universal Windows Platform has made a long way and now greatly supports building Windows 10 desktop applications. The sample application Van Ardsel Inventory greatly shows how a business app can look like with UWP. With the Windows UI Library , Microsoft plans to make UWP XAML controls open source. This library is available in preview on NuGet to use new UWP controls with older versions of Windows 10. The Windows Template Studio gives you a fast path to start with UWP and use the various features easily.

In case you would like to start now go ahead and build great Windows 10 apps.

In case you still need to support Windows 7 users, and have an existing WPF app that cannot be changed to UWP in the short time, you can integrate Windows 10 features in this app. Information what you can do here is covered in the next article of this series.

If this information motivated you building Windows 10 apps with UWP, consider buying me a coffee which helps me staying up longer and writing more articles.


Desktop Applications with XAML. Part 1: UWP

More information on XAML and writing UWP applications is in my book Professional C# 7 and .NET Core 2.0 , and in my Programming Windows Apps workshops .

Enjoy learning and programming!

Christian

Important links from the article:

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

代码区博客精选文章
分页:12
转载请注明
本文标题:Desktop Applications with XAML. Part 1: UWP
本站链接:https://www.codesec.net/view/610825.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(52)