在项目开发的过程,通常会遇到一些表格数据的绑定,因为没有WPF的开发经验所以一边摸索一边开发,所幸WPF的上手难度不大,开发过程较为顺利。不过在使用DataGrid的时候还是遇到了一点阻绊遇。所以在这里讲一下这个DataGrid应该怎么用,以及要注意的事情。
DataGrid是个非常实用的控件,可以用来展示及获取较为复杂的数据结构。
要在WPF下使用DataGrid并绑定数据,大致操作如下:
1、在资源视图xml文件中添加DataGrid,并设置绑定,如下。
<Window x:Class="Wpfdemo.Window1"
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:Wpfdemo"
mc:Ignorable="d"
Title="Window1" Height="300" Width="300">