WinUI 3 demo report

tags: WPF  UWP  WinUI  Windows  

1. What is WinUI 3

At the Microsoft Build 2020 developer conference, the WinUI team announced the publicly previewable WinUI 3 Preview 1, which allows developers to use WinUI in Win32. WinUI 3 Preview 1 includes a new VisualStudio project template that can create C# and C++/Win32 projects for .NET 5. Technically speaking, WinUI 3 separates the XAML, Composition, and Input layers of UWP and distributes them independently to Win32 applications targeting Windows 10 version 1803 and later through NuGet.

WinUI 3 is suitable for Win32 and UWP. This article mainly discusses the Win32 situation.

2. Understand WinUI 3

In the past, we always complained that WPF did not provide new themes for many years, did not provide new controls, and did not improve performance. Now Microsoft simply provides all the new WinUI 3 to desktop development, nothing more than WPF.

To put it simply, the UWP development experience is not good (it is hard to say a word about this topic), and if there is a bug, you must wait for the Windows update in the second half of the year to be fixed, but Microsoft developers concentrate on adding various functions to the UWP UI layer; NET Core is updated very quickly, but few people are interested and motivated to make drastic improvements to the old WPF UI layer. So WinUI separates the UI layer of UWP from the rest of the Windows SDK and will transfer it from Windows to Nuget. Now build a C++ or C# (.NET 5) program, and then install a WinUI 3 package and a UI layer from Nuget. An application based on Fluent Design, which is touch-friendly and has unparalleled performance, is born.

The above figure lists some of the features of WinUI 3 compared with other platforms. In addition, WinUI 3 has many benefits, such as open source, faster updates, and updates are not tied to the system version. More detailed content depends on Microsoft itself. Promote it:

WinUI - The modern native UI platform of Windows.

But it will take a year or a half to use WinUI 3. The following is the release roadmap given by Microsoft. At present, we can only use the Preview version as an early adopter.

3. Try WinUI 3

To try WinUI 3, you must first have a computer with Windows 10 1803 or above (WinUI 3 supports at least 1803), and then you also need to use Visual Studio 2019 16.7 or above (currently only installpreview edition). When installing Visual Studio, select all of the following workloads:

  • .NET desktop development
  • Universal Windows platform development
  • Desktop development using C++
  • C++ (V142) Universal Windows Platform Tools Optional Components for Universal Windows Platform Load

of course .NET 5.0 Also install it.

Then download and install the WinUI 3 Project Templates extension at https://aka.ms/winui3/previewdownload, so that you can create WinUI projects in Visual Studio.

Optional C++ or C#, here I choose C# "Blank App, Packaged
(WinUI in Desktop)" project, and select the corresponding Windows platform:

After the project was created, Visual Studio generated two projects. The first one contains the code of the application. The code structure is basically the same as UWP, except that Package.appxmanifest and some pictures for packaging the application are missing. From the dependencies, you can see that the project has installed the Microsoft.WinUI 3 package. You can see from the project properties that this is a .NET 5 project.

The second project generated by Visual Studio is a Windows application packaging project that can be configured to generate the application into an MSIX package suitable for deployment. That is to say, the part used for packaging in the UWP project is independent. This project should also be the start-up project of the solution. Applications created after running this project will be added to the start menu, which is the same as UWP.

So far as expected, I also tried to port UWP applications to WinUI, basically just need toWindows.UI Namespace changed toMicrosoft.UIThat's it, the XAML and C# code does not change at all. It's a pity that WinUI is still very rudimentary, and there is no WinUI version of the UWP packages released by Microsoft, such as Win2D and Community Toolkit. And there is no design view, and XAML view has no IntelliSense. Now it is very difficult to do some interesting projects with WinUI. However, judging from the current difficulty of transplantation, it should be possible to fully apply the UWP UI development experience to WinUI after the official release in the future.

4. Compare with WPF and UWP

Since the WinUI 3 development model is very similar to WPF and UWP, I am of course very interested in the comparison between them.

name

Let me talk about naming first, "WinUI" is just the name Win. "UWP" is too elegant. I bet that some domestic UWP developers (such as me) can't spell out the full name of UWP; "WPF" is better, but the meaning of WPF is also very confusing. Windows UI is called WinUI for short, and its meaning and pronunciation are very clear. But these three are much better than "Xamarin" that many people don't read.

But with WinUI 3, someone will ask "What about WinUI 2?" WinUI 2 is a UWP control library, and of course it can only be used on UWP. This is very embarrassing. WinUI 3 and 2 are not the same concept at all. It is really easy to confuse people. Maybe we will add the suffix in the future.3 Remove (I’m often too lazy to write this article3). And the namespace of the code in WinUI 2 isWindows.UI At the beginning, in WinUI 3 becomesMicrosoft.UI According to the experience of renamed Office 365 to Microsoft 365 and Bind Ads to Microsoft Advertising, won’t it be possible that WinUI will be renamed Microsoft UI, or MiUI for short?

Authority

The authority aspect is a bright spot of WinUI, because it is essentially a Win32 program, you can just let it go. Relative UWP has very strict permission restrictions, and when developing UWP, it often feels tied. For example, the following code, most WPF developers can hardly imagine that just minimize the UWP program, it will not run properly:

int count = 0;
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += (s, e) =>
  {
      myButton.Content = count++;
  };
timer.Start();

The life cycle of UWP is as shown in the figure above. When UWP is running in the background or suspended state, the application is basically in a suspended state, and it does not handle UI functions. I understand that this is because UWP is designed to save power and security, but it is really inconvenient for developers. The WinUI application is basically a Win32 application, and it seems that there will be no such pits.

Development experience

Speaking of development experience, WPF is normal at any rate, the design view of Visual Studio runs normally, and compiles quickly. UWP compilation is very slow, the design view often has problems, and Blend can also make designers run away from time to time. Even if a UWP App is completed according to the official documentation, even a single line of code is not changed, it may crash after being published to the store. As for the app store, a thousand words really converge into a flower head.

Now WinUI's XAML view does not even have IntelliSense, and there is no design view, so it is impossible to talk about the development experience. It's hard to guess what will happen when it is officially released, I hope it is at least consistent with WPF.

performance

WPF always gives people the impression of "slow", in addition to the lack of computer performance when it first came out (10 years ago) leaving a stereotype, there is another main reason: it is really slow.

UWP's XAML has excellent performance. In addition to taking care of the poor performance of Windows Phone that no longer exists, many control templates have been carefully designed and greatly simplified.

In order to verify the performance of WinUI, I wrote the following codes, and then ported them to WPF .Net Framework 4.8, WPF .NET 5, UWP, WinUI (WPF and UWP/WinUI codes are slightly different):

for (int i = 0; i < 50; i++)
{
    var rectangle = new Rectangle
    {
        Height = 500,
        Width = 500,
        Opacity = ((double)i + 40) / 100d,
        RadiusX = 108,
        RadiusY = 98,
        StrokeThickness = 3,
        Stroke = new SolidColorBrush(Color.FromArgb(255, 75, 75, (byte)(i * 250d / 50d))),
        RenderTransformOrigin = new Point(0.5, 0.5)
    };
    Root.Children.Add(rectangle);
    var angle = i * 360d / 50d;
    var transform = new RotateTransform
    {
        Angle = angle
    };

    rectangle.RenderTransform = transform;

    var storyboard = new Storyboard();
    storyboard.Children.Add(new DoubleAnimation { Duration = TimeSpan.FromSeconds(1), From = angle, To = angle + 360 });
    Storyboard.SetTarget(storyboard, transform);
    Storyboard.SetTargetProperty(storyboard, "Angle");
    storyboard.RepeatBehavior = RepeatBehavior.Forever;
    storyboard.Begin();
}

The above code is to rotate 50 rectangles, which is a test of the performance of WPF. The result can be said to be unexpected.

CPU RAM GPU
WPF .NET Framework 4.8 12 60 76
WPF .NET 5.0 12 85 72
UWP 3 28 36
WinUI 5 65 95

My environment is i7-6820HQ and integrated graphics. The WPF platform occupies more than 70% of the GPU, which I can roughly guess. UWP is very smooth, GPU only occupies half of WPF, CPU and memory have excellent performance, but I thought it would be lower.

WinUI, with thick eyebrows and big eyes, I really did not expect that not only did it drop frames significantly, it also occupies almost 100% of the GPU, which means that it can't even run such simple code. () By the way, reducing the number of rotated rectangles in the test code to 10, the WPF program occupies 32% of the GPU, while WinUI occupies more than 70%. )

From the above data, it can be basically explained that WinUI is still far away from the design goal, after all, it is a preview version, and there is still a year or a half to optimize it slowly.

5 Conclusion

Generally speaking, Microsoft is ambitious, but the preview version of WinUI that is now coming out is still far behind, the function is not perfect, and the performance is not as expected. I think the general direction is right. WinUI is a new tool and opportunity for C++, WPF, and UWP developers. You can pay attention to it.

6. Q & A

What about Windows 7?

According to the roadmap announced by Microsoft, including factors such as ticket skipping, Windows 7 has stopped updating for a long time when WinUI is really available. By then, the share of Windows 7 may have fallen to a level that developers will not care about.

Wpf or WinUI based on .NET Core?

If you don’t want to spend your energy on migrating existing projects to WinUI, or have no confidence in WinUI from UWP, or are reluctant to users of Windows 7 and have no need for touch, you can of course continue to choose WPF. WPF based on .NET Core will be very good Good choice.

MAUI or WinUI?

MAUI is still in the very far future (November 2021), I haven't tried it, so it's not easy to comment. If there is a cross-platform requirement, of course, you can only choose MAUI. If the WinUI team has achieved the ultra-high performance that MAUI can't match, then choose WinUI. However, the name MAUI is too common/common, and may be forced to change the name.

What about UWP?

UWP with restricted permissions can be said to be harmless to humans and animals, and it may also be a good choice for users. And UWP also supports platforms such as Xbox and Hololens, and it seems that there is still a market for it.

What about Winform?

Only by forgetting the past can one live well.

Does WinUI have a future?

I have done Silverlight development for many years, bought 5 or 6 Windows Phone phones, and wrote dozens of UWP articles. Based on my rich experience, I can be sure that WinUI has a future.

8. Reference

WinUI - The modern native UI platform of Windows.

Introducing WinUI 3 Preview 1 - Windows Developer Blog

Get started with WinUI 3 for desktop apps Microsoft Docs

GitHub - microsoft_microsoft-ui-xaml

Windows UI Library Roadmap

WinUI 3.0_ The future of Windows controls

Intelligent Recommendation

uevent event report demo

1. Drive reporting 2. Report and print 3.vold receiving event...

3. Report

input_event #define INPUT_IGNORE_EVENT    0 #define INPUT_PASS_TO_HANDLERS    1 #define INPUT_PASS_TO_DEVICE    2 #define INPUT_SLOT    &nbs...

[Experience and Experience] A System Demo Report

Yesterday, a system demonstration was conducted for customers of the city's data resource center. In this demonstration, in order to solve the problem that many people separately demonstrated differen...

JUnit 3 Demo

1.Maven Dependency   2.Project Directory   3.src/main/java Calculator.java   Calculator2.java   Largest.java   DeleteAll.java   MyStack.java   4.src/test/java Calcul...

More Recommendation

CEF demo-configuration (3)

After downloading and compiling the CEF code, open the project as shown: Right click to add your project After completion, right-click and select project properties, Select libcef_dll_wrapper and clic...

MASKRCNN (3) demo.

One   use TF MODEL_DIR:  Save log, and trained model IMAGE_DIR: Image storage path images/ COCO_MODEL_PATH:mask_rcnn_coco.h5Downloadedcoco model Two   configuration Configuration information read...

Selenium 3 + Python 3 Demo

Selenium 3 + Python 3 Demo The new company requires Python and has plans to go to Web automation, so I've been learning Python and Selenium recently. This article first comes with a simple demo, other...

Vue 3(alpha) Official Demo Demo

https://github.com/vuejs/vue-next-webpack-preview/blob/master/src/App.vue...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top