首页 > 解决方案 > 将 WinUI 控件添加到 UWP 应用程序

问题描述

我正在尝试对我的 UWP 应用程序使用新的 WinUI 工具包 TreeView/TeachingTip/... 控件。我已经从 Nudget 包中添加了参考 Microsoft.UI.Xaml。

<Page 
    x:Class="UWPInVS2019.Login"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UWPInVS2019"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:WinCon="using:Microsoft.UI.Xaml.Controls"
    mc:Ignorable="d" 
>
<Grid>
<Button />
<WinCon:TeachingTip/>
</Grid>

我收到以下错误消息 在此处输入图像描述

标签: uwp-xamlwinui

解决方案


问题是您错过了添加XamlControlsResources到 UWP 项目 App.xaml 文件中的内容。请将以下 xaml 代码添加到 App.xaml 文件中。

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

更多细节请参考WinUI 官方教程。


推荐阅读