简体   繁体   English

无法使用 Windows 社区工具包中的 GridView 控件

[英]Unable to use GridView Control from Windows Community Toolkit

I'm having a problem getting the GridView control from the Windows Community Toolkit working in my WinUI project.我从 Windows 社区工具包中获取 GridView 控件在我的 WinUI 项目中工作时遇到问题。 I've added the Microsoft.Toolkit.Uwp.UI.Control nuget package, which has installed successfully, and I can see it added to the correct project in solution explorer.我已经添加了 Microsoft.Toolkit.Uwp.UI.Control nuget 包,它已成功安装,我可以在解决方案资源管理器中看到它已添加到正确的项目中。

My XAML (some irrelevant code removed for brevity) is as follows:我的 XAML(为简洁起见删除了一些不相关的代码)如下:

<Window
    x:Class="SampleApp.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" SizeChanged="SizeChanged"
    mc:Ignorable="d">
        (other controls/content removed for brevity)
        <controls:DataGrid (code removed for brevity)>
        </controls:DataGrid>
</Window>

When trying to add the control to the XAML file, the line xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" gives the compiler error:尝试将控件添加到 XAML 文件时, xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"行给出编译器错误:

XLS0429 Undefined namespace. XLS0429 未定义的命名空间。 The 'using' URI refers to a namespace 'Microsoft.Toolkit.Uwp.UI.Controls' that could not be found. “使用” URI 指的是找不到的命名空间“Microsoft.Toolkit.Uwp.UI.Controls”。

...and the line starting <controls:DataGrid gives the compiler error: ...并且以<controls:DataGrid开头的行给出了编译器错误:

XLS0414 The type 'controls:DataGrid' was not found. XLS0414 找不到类型“控件:DataGrid”。 Verify that you are not missing an assembly reference and that all referenced assemblies have been built.确认您没有丢失程序集引用并且所有引用的程序集都已构建。

I've been following examples such as this one , but I'm not getting anywhere.我一直在关注诸如this one之类的示例,但我一无所获。

Can anyone point me in the right direction?谁能指出我正确的方向?

You've used the tag 'winui-3' yet your package is for UWP / WinUI 2.您使用了标签“winui-3”,但您的包适用于 UWP / WinUI 2。

Pick one and try again.选择一个,然后再试一次。

https://www.nuget.org/packages/CommunityToolkit.WinUI.UI.Controls/ https://www.nuget.org/packages/CommunityToolkit.WinUI.UI.Controls/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM