c# wpf datagrid 简单试验

1.概要

datagrid 一个列表类的控件

2.代码

<Window x:Class="WpfApp2.Window3"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp2"
        mc:Ignorable="d"
        Title="Window3" Name="win" Height="450" Width="800">
    <Grid>
        <DataGrid Name="dataview" >
            
        </DataGrid>
    </Grid>
</Window>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApp2
{
    /// <summary>
    /// Window3.xaml 的交互逻辑
    /// </summary>
    public partial class Window3 : Window
    {
        public List<Book> BookList = new List<Book>();
        public Window3()
        {
            InitializeComponent();
            initView();
            dataview.ItemsSource = BookList;
        }

        public void initView()
        {
            BookList.Add(new Book() { Title = "三国演义", Author = "罗贯中", Time = DateTime.Now.AddYears(-200) });
            BookList.Add(new Book() { Title = "红楼梦", Author = "曹雪芹", Time = DateTime.Now.AddYears(-150) });
            BookList.Add(new Book() { Title = "西游记", Author = "吴承恩", Time = DateTime.Now.AddYears(-230) });
        }
    }
}

public class Book
{
    public required string Title { get; set; }
    public required string Author { get; set; }
    public DateTime Time { get; set; }
}

3.运行结果

相关推荐
gu201 小时前
c#编程:学习Linq,重几个简单示例开始
开发语言·学习·c#·linq
pchmi5 小时前
CNN常用卷积核
深度学习·神经网络·机器学习·cnn·c#
yuanpan6 小时前
23种设计模式之《组合模式(Composite)》在c#中的应用及理解
开发语言·设计模式·c#·组合模式
滴_咕噜咕噜7 小时前
C#基础总结:常用的数据结构
开发语言·数据结构·c#
万兴丶10 小时前
Unity 适用于单机游戏的红点系统(前缀树 | 数据结构 | 设计模式 | 算法 | 含源码)
数据结构·unity·设计模式·c#
程序猿多布11 小时前
C#设计模式 学习笔记
设计模式·c#
软件黑马王子18 小时前
Unity游戏制作中的C#基础(5)条件语句和循环语句知识点全解析
游戏·unity·c#
shepherd枸杞泡茶18 小时前
第3章 3.3日志 .NET Core日志 NLog使用教程
c#·asp.net·.net·.netcore
界面开发小八哥21 小时前
界面组件DevExpress WPF中文教程:Grid - 如何显示和隐藏列?
wpf·界面控件·devexpress·ui开发·.net9
虚假程序设计1 天前
python用 PythonNet 从 Python 调用 WPF 类库 UI 用XAML
python·ui·wpf