c# - 如何将 ObservableCollections 绑定(bind)到 ItemsSource?

标签 c# wpf

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 绑定(bind)到 ItemsSource?

最佳答案

您想将 ItemSource 设置为您在构造函数中创建的 ObservableCollection 的实例:

RadGridView1.ItemsSource = _MyObject;

关于c# - 如何将 ObservableCollections 绑定(bind)到 ItemsSource?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4303557/

相关文章:

C# 上传前过滤文件扩展名

c# - IDisposable.Dispose() 作为方法名称是什么意思?

c# - 启用 exchange 2010 邮箱

c# - 根据组合框选择从 MySQL 表中选择值?

WPF:将ImageSource转换为流

wpf - 如何知道要在 FindWindowByClassName InnoSetup 函数中使用的 WPF 应用程序的类名

c# - 查找左上角单元格的坐标?使用 EPPlus

c# - 如何处理用户提交的正则表达式的无休止匹配

wpf - 如何在 WPF 中声明将 Itemsource 作为枚举值的组合框 itemTemplate?

c# - 在while循环中替代线程 sleep