WEB开发网
开发学院图形图像Flash Using The Silverlight DataGrid 阅读

Using The Silverlight DataGrid

 2008-10-24 11:47:00 来源:WEB开发网   
核心提示: Step 2 A: Name the DataGrid and buildBefore we go to the code behind you will want to be sure to give the DataGrid a name such as "dg".

Step 2 A: Name the DataGrid and build

Before we go to the code behind you will want to be sure to give the DataGrid a name such as "dg". Also be sure to build so that you can reference the DataGrid in code:

<my:DataGrid x:Name="dg" ></my:DataGrid>

Step 2 B: Create and Set the Items Source

Now that the DataGrid is ready to have its ItemsSource set, go to the Page's constructor located in the code behind file for Page.xaml (A handy shortcut to do this from within Page.xaml is F7) and add the following line below InitializeComponent:

C#

public Page()
{
  InitializeComponent();
  dg.ItemsSource = "H e l l o W o r l d !".Split();
}

VB

Public Sub New()
  InitializeComponent()
  dg.ItemsSource = "H e l l o W o r l d !".Split()
End Sub

(If you get the build error: "The name 'dg' does not exist in the current context" with the code above be sure to build a second time so that the name has a chance to propagate)

One of the easiest ways to generate an IEnumerable collection is String.Split. When the resulting array is set as the ItemsSource of the DataGrid a column will be automatically generated since AutoGenerateColumns is true. When you run the application, it will look like this:

上一页  1 2 3 4 5 6  下一页

Tags:Using The Silverlight

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接