Implementing a DataGrid Control
<UserControl x:Class='SilverlightApplication3.MainPage'
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'
d:DesignWidth='640'
d:DesignHeight='480'
xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
<Grid x:Name="LayoutRoot" Background="White">
<my:DataGrid x:Name="dGrid"
AutoGenerateColumns="True"
RowBackground="White"
AlternatingRowBackground="LightGray"
HeadersVisibility="Column"
Height="180" Width="380"/>
</Grid>
</UserControl>
//File:Page.xaml.cs
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace SilverlightApplication3
{
public partial class MainPage : UserControl
{
List<Movie> movieList = new List<Movie>();
public MainPage()
{
InitializeComponent();
initData();
dGrid.ItemsSource = movieList;
}
private void initData()
{
movieList.Add(new Movie()
{
Title = "A",
Rating = "B",
Year = 2007,
Available = true
});
}
}
public class Movie
{
public string Title { get; set; }
public int Year { get; set; }
public string Rating { get; set; }
public bool Available { get; set; }
}
}
Related examples in the same category