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

Using The Silverlight DataGrid

 2008-10-24 11:47:00 来源:WEB开发网   
核心提示: This is a little better, but so far this could be done with a ListBox.Lets add some more complicated data so that we actually need to use a Data

Using The Silverlight DataGrid

This is a little better, but so far this could be done with a ListBox. Lets add some more complicated data so that we actually need to use a DataGrid.

Add a new class to your Silverlight project (not the Web project) and name it "Data".

Using The Silverlight DataGrid

Then add a few properties to bind to.

C#

If you are using C#, you can use the great 3.0 Automatic Properties feature.

public class Data
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public int Age { get; set; }
  public bool Available { get; set; }
}

VB

Public Class Data
  Private _firstName As String
  Private _lastName As String
  Private _age As Integer
  Private _available As Boolean
  Property FirstName() As String
    Get
      Return _firstName
    End Get
    Set(ByVal value As String)
      _firstName = value
    End Set
  End Property
  Property LastName() As String
    Get
      Return _lastName
    End Get
    Set(ByVal value As String)
      _lastName = value
    End Set
  End Property
  Property Age() As Integer
    Get
      Return _age
    End Get
    Set(ByVal value As Integer)
      _age = value
    End Set
  End Property
  Property Available() As Boolean
    Get
      Return _available
    End Get
    Set(ByVal value As Boolean)
      _available = value
    End Set
  End Property
End Class

Once the Data class is defined, it can now be used to provide data for the DataGrid. Go back to the code behind file for Page.xaml and replace the previous ItemsSource assignment with the following. A useful trick here is to use the C# and VB 3.0 Object Initializer feature to initialize the Data objects as we add them to the List.

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

Tags:Using The Silverlight

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