DataContextDataContext context1 = new DataContextDataContext();
public MainWindow()
{
InitializeComponent();
DataContext = new ObservableCollection<MyObject>();
RadGridView1.Filtered+=new EventHandler<GridViewFilteredEventArgs>(RadGridView1_Filtered);
ObservableCollection<MyObject> _MyObject = new ObservableCollection<MyObject>();
foreach (var p in context1.Students)
{
_MyObject.Add(new MyObject { ID = p.StudentID, Name = p.StudentFN });
}
}
void RadGridView1_Filtered(object sender, GridViewFilteredEventArgs e)
{
RadGridView1.ItemsSource = ObservableCollection<MyObject>();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
public class MyObject
{
public int ID { get; set; }
public string Name { get; set; }
}
你如何將我的ObservableCollections綁定到ItemsSource?如何將ObservableCollections綁定到ItemsSource?
protip:`ObservableCollection MyObjects {get; set;}`綁定到字段不起作用(我很驚訝它在選定的答案;可能是因爲它是一個集合),如果你開始習慣這種習慣,你會花幾天的時間搞清楚爲什麼你的綁定失敗。另外,您可能想查看框架指南。 –
Will
2010-11-29 12:45:42