主题 : Getting started with the Windows UI 2 Library
千山同一月 万户尽皆春 千江有水千江月 万里无云万里天
级别: 总版主

UID: 998
精华: 0
发帖: 605026
威望: 529007 点
无痕币: 14 WHB
贡献值: 0 点
在线时间: 62136(时)
注册时间: 2008-12-25
最后登录: 2024-04-23

0 Getting started with the Windows UI 2 Library

Windows UI Library 2.7 is the latest stable version of WinUI that can be used for building production UWP applications (and desktop applications using XAML Islands).
The library is available as a NuGet package that can be added to any new or existing Visual Studio project.
Note
For more information on building Windows desktop and UWP apps with the latest version of WinUI 3, see Windows UI Library 3.
Download and install the Windows UI Library
    Download Visual Studio 2019 and ensure you choose the Universal Windows Platform development Workload in the Visual Studio installer.
    Open an existing project, or create a new project using the Blank App template under Visual C# -> Windows -> Universal, or the appropriate template for your language projection.
    Important
    To use WinUI 2.7, you must set TargetPlatformVersion >= 10.0.18362.0 and TargetPlatformMinVersion >= 10.0.15063.0 in the project properties.
    In the Solution Explorer panel, right click on your project name and select Manage NuGet Packages.
     
    The Solution Explorer panel with the project right-clicked and the Manage NuGet Packages option highlighted.
    In the NuGet Package Manager, select the Browse tab and search for Microsoft.UI.Xaml or WinUI. Select which Windows UI Library NuGet Packages you want to use (the Microsoft.UI.Xaml package contains Fluent controls and features suitable for all apps). Click Install.
    Check the "Include prerelease" checkbox to see the latest prerelease versions that include experimental new features.

    The NuGet Package Manager dialog box showing the Browse tab with winui in the search field and Include prerelease checked.
    Add the Windows UI (WinUI) Theme Resources to your App.xaml file.
    There are two ways to do this, depending on whether you have additional application resources.
    a. If you don't need other application resources, add the WinUI resources element <XamlControlsResources as shown in the following example:
    <Application    x:Class="ExampleApp.App"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    RequestedTheme="Light">    <Application.Resources>        <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />    </Application.Resources></Application>[/pre]b. If you need more than one application resource, add the WinUI resources element <XamlControlsResources in a <ResourceDictionary.MergedDictionaries> as shown here:
    <Application    x:Class="ExampleApp.App"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    RequestedTheme="Light">    <Application.Resources>        <ResourceDictionary>            <ResourceDictionary.MergedDictionaries>                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />                <ResourceDictionary Source="/Styles/Styles.xaml"/>            </ResourceDictionary.MergedDictionaries>        </ResourceDictionary>    </Application.Resources></Application>[/pre]Important
    The order of resources added to a ResourceDictionary affects the order in which they are applied. The XamlControlsResourcesdictionary overrides many default resource keys and should therefore be added to Application.Resources first so that it doesn't override any other custom styles or resources in your app. For more information on resource loading, see ResourceDictionary and XAML resource references.
    Add a reference to the WinUI package to both XAML pages and/or code-behind pages.
      In your XAML page, add a reference at the top of your page
      xmlns:muxc="using:Microsoft.UI.Xaml.Controls"[/pre]In your code (if you want to use the type names without qualifying them), you can add a using directive.
      using MUXC = Microsoft.UI.Xaml.Controls;[/pre]
Additional steps for a C++/WinRT project
When you add a NuGet package to a C++/WinRT project, the tooling generates a set of projection headers in your project's \Generated Files\winrt folder. To bring those headers files into your project, so that references to those new types resolve, you can go into your precompiled header file (typically pch.h) and include them. Below is an example that includes the generated header files for the Microsoft.UI.Xaml package.
// pch.h...#include "winrt/Microsoft.UI.Xaml.Automation.Peers.h"#include "winrt/Microsoft.UI.Xaml.Controls.Primitives.h"#include "winrt/Microsoft.UI.Xaml.Media.h"#include "winrt/Microsoft.UI.Xaml.XamlTypeInfo.h"...[/pre]For a full, step-by-step walkthrough of adding simple support for the Windows UI Library to a C++/WinRT project, see A simple C++/WinRT Windows UI Library example.
Contributing to the Windows UI Library
WinUI is an open source project hosted on GitHub.
We welcome bug reports, feature requests and community code contributions in the Windows UI Library repo.
Other resources
If you're new to UWP, then we recommend that you visit the Getting Started with UWP Development pages on the Developer portal.
Feedback
级别: 六行秋雁
UID: 20029
精华: 0
发帖: 8736
威望: 11653 点
无痕币: 30542 WHB
贡献值: 0 点
在线时间: 1740(时)
注册时间: 2008-04-09
最后登录: 2024-04-23

楼主是人才。
千山同一月 万户尽皆春 千江有水千江月 万里无云万里天
级别: 总版主

UID: 998
精华: 0
发帖: 605026
威望: 529007 点
无痕币: 14 WHB
贡献值: 0 点
在线时间: 62136(时)
注册时间: 2008-12-25
最后登录: 2024-04-23

这个可以进来看看,了解一下。
知足常乐
级别: 十方秋水

UID: 23
精华: 1
发帖: 261109
威望: 117121 点
无痕币: 2321 WHB
贡献值: 0 点
在线时间: 9390(时)
注册时间: 2007-11-24
最后登录: 2024-04-22

看看了解一下,谢谢总版分享!
事能知足心常乐 人到无求品自高
级别: 十方秋水

UID: 88
精华: 0
发帖: 130083
威望: 221815 点
无痕币: 107273 WHB
贡献值: 0 点
在线时间: 51933(时)
注册时间: 2008-03-18
最后登录: 2024-04-23

了解一下。谢谢楼主分享。
级别: 七朵秋菊

UID: 219073
精华: 0
发帖: 26465
威望: 22589 点
无痕币: 108 WHB
贡献值: 0 点
在线时间: 1504(时)
注册时间: 2013-09-06
最后登录: 2024-04-23

谢楼主辛苦分享!
级别: 六行秋雁
UID: 20029
精华: 0
发帖: 8736
威望: 11653 点
无痕币: 30542 WHB
贡献值: 0 点
在线时间: 1740(时)
注册时间: 2008-04-09
最后登录: 2024-04-23

楼主是人才。
级别: 六行秋雁
UID: 20029
精华: 0
发帖: 8736
威望: 11653 点
无痕币: 30542 WHB
贡献值: 0 点
在线时间: 1740(时)
注册时间: 2008-04-09
最后登录: 2024-04-23

楼主是人才。
Total 0.045671(s) query 4, Time now is:04-23 21:11, Gzip enabled 粤ICP备07514325号-1
Powered by PHPWind v7.3.2 Certificate Code © 2003-13 秋无痕论坛