Reputation: 193
I want to use DataGrid in WinUI 3, and I noticed that the WinUI3 gallery and the Windows Community Toolkit gallery have different DataGrid table controls. I can’t find where the DataTable is located.
I found the DataGrid on NuGet, but I also saw "DataTable" mentioned in the Windows Community Toolkit Gallery under Controls > Layout > DataTable. To use controls:DataColumn, as shown in the Windows Community Toolkit Gallery samples, which NuGet package should I install?
This is part of the sample I found in the gallery.
<Page x:Class="DataTableExperiment.Samples.DataTableSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:DataTableExperiment.Samples"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<ListView ItemsSource="{x:Bind InventoryItems}">
<ListView.Header>
<controls:DataTable Margin="12,0,0,0">
<controls:DataColumn Content="Id"
DesiredWidth="80" />
<controls:DataColumn MinWidth="120"
CanResize="True"
Content="Name" />
Upvotes: 2
Views: 268
Reputation: 13666
To use the DataTable control from CommunityToolkit-Labs:
On the NuGet Package Manager, go to Settings (the gear icon) and add the Lab's NuGet package source from Settings.
Enable only the Lab's NuGet package source.
Enable Initial prerelease.
Search for CommunityToolkit.Labs.WinUI.Controls.DataTable
and install it.
Add the corresponding namespace. For example:
xmlns:labs="using:CommunityToolkit.WinUI.Controls"
Use the control:
<labs:DataTable />
UPDATE
If you face some namespaces issues, you might be hitting this issue. Try updating your target framework.
<TargetFramework>net9.0-windows10.0.22621.0</TargetFramework>
<WindowsSdkPackageVersion>10.0.22621.38</WindowsSdkPackageVersion>
Upvotes: 2
Reputation: 3024
It seems that CommunityToolkit.DataTable control is not public, the link is invalid. https://github.com/CommunityToolkit/Windows/tree/main/components/DataTable
It is recommended that you use DataGrid. However, you can find the Labs-components here https://github.com/CommunityToolkit/Labs-Windows/tree/main/components/DataTable
Upvotes: 1