Need help in DataGrid

Apr 14, 2009 at 5:04 AM
Hi, I am relatively new to WPF and have been trying to bind an array of  object to my WPF Datagrid but only a single empty row appear each time. Is it possible to implement a binding to a object array or does it has to be an observable collection?

I set my DataGrid.DataContext=FacilityList.Facility where a FacilityList instance of one object was returned from the WCF service and my watch show that the DataContext has the array[1].

My object class is also used in a WCF service data definition. the code are as below.
Hope someone can tell me how to get around this. Thanks.

 

 

using

 

System;

 

using

 

System.Runtime.Serialization;

 

 

namespace WcfForSql.DataContracts.List.Elelments

 

{

[

DataContract(Namespace = "http://FacilityStatus")]

 

 

public class Facility

 

 

 

{

 

[

DataMember(Name = "Name")]

 

 

public String Name;

 

[

DataMember(Name = "SlotStatus")]

 

 

public int[] slotsStatus;

 

}

 

public enum Status:int

 

 

 

{

 

NOT_AVAILABLE = 0,

AVAILABLE = 1,

BOOKED_BY_USER = 2,

BOOKED_BY_OTHERS = 3

}

}

 

 

 

 

 


using

 

System;

 

using

 

System.Runtime.Serialization;

 

using

 

WcfForSql.DataContracts.List.Elelments;

 

namespace

 

WcfForSql.DataContracts.List

 

{

[

DataContract]

 

 

public class UserFacilityList

 

{

 

private string userName = "Hello ";

 

 

private Facility[] facilityList;

 

[

DataMember]

 

 

public string UserName

 

{

 

get { return userName; }

 

 

set { userName = value; }

 

}

[

DataMember]

 

 

public Facility[] FacilityList

 

{

 

get { return facilityList;}

 

 

set { facilityList = value; }

 

}

}

}


<

 

toolkit:DataGrid Width="1014" Height="456" IsSynchronizedWithCurrentItem="True"

 

 

Canvas.Left="6" Canvas.Top="40" x:Name="DataGrid1"

 

 

ItemsSource="{Binding}" AutoGenerateColumns="true"/>

 

Apr 14, 2009 at 5:09 AM
sorry for the formatting guys... don't know how all the space came about....