通过 Nuget 搜索 Microsoft.Toolkit.Uwp.UI.Controls.DataGrid 安装库,在XAML文件中添加引用库
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
<Page x:Class="App2.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App2" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid> <controls:DataGrid x:Name="DataGrid" > </controls:DataGrid> </Grid> </Page>
using System.Collections.Generic; using Windows.UI.Xaml.Controls; // https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x804 上介绍了“空白页”项模板 namespace App2 { /// <summary> /// 可用于自身或导航至 Frame 内部的空白页。 /// </summary> public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); DataGrid.ItemsSource = new List<Foo>() { new Foo(){ Name = "小明", Age = 15 }, new Foo(){ Name = "小王", Age = 16 }, }; } public class Foo { public string Name { get; set; } public int Age { get; set; } } } }