DataGrid入门级问题,求教
这是XAML代码
<navigation:Page xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="SLClient.Test" 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" mc:Ignorable="d" xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation" d:DesignWidth="640" d:DesignHeight="480" Title="Test Page"> <Grid x:Name="LayoutRoot"> <data:DataGrid Name="dataGrid" Margin="3,3,3,3"></data:DataGrid> </Grid></navigation:Page>
using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using System.Windows.Navigation;namespace SLClient{ public partial class Test : Page { public Test() { InitializeComponent(); List<DataItem> datas = new List<DataItem>(); datas.Add(new DataItem { ID = "1", Text = "item1" }); datas.Add(new DataItem { ID = "2", Text = "item2" }); datas.Add(new DataItem { ID = "3", Text = "item3" }); this.dataGrid.ItemsSource = datas; } } class DataItem { public String ID { get; set; } public String Text { get; set; } }}
public class DataItem { public String ID { get; set; } public String Text { get; set; } }