首页 > 解决方案 > TabView suddenly missing from UWP

问题描述

Was trying to implement a TabView in my UWP project yesterday but it doesn't show up in the ToolBox and if I add it via code it says

TabView is not supported in a Windows Universal Project.

Though the documentation on the website is fairly recent and clear: https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/tab-view

I put the UWP requirement on latest Windows 10 build. Running Visual Studio 2019 Enterprise.

More information or help is appreciated.

标签: uwptabs

解决方案


从这个TabView 的文档中可以看到,TabView 在Microsoft.UI.Xaml.Controls命名空间下,适用于 WinUI。因此,您需要安装Microsoft.UI.Xaml nuget 包并将 Windows UI (WinUI) 主题资源添加到您的 App.xaml 资源中。然后在 xaml 中添加命名空间以使用它。

应用程序.xaml:

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

MainPage.xaml:

<Page
    ......
    xmlns:control="using:Microsoft.UI.Xaml.Controls">

    <Grid>
        <control:TabView HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            ......
        </control:TabView>
    </Grid>
</Page>

推荐阅读