WPF DataGrid绑定到XAML中的DataTable

WPF DataGrid绑定到XAML中的DataTable,wpf,xaml,datagrid,binding,datatable,Wpf,Xaml,Datagrid,Binding,Datatable,我对WPF/XAML完全陌生。我正在尝试编写XAML代码来将DataTable绑定到DataGrid。我有一个自定义DataContainer类的实例,它实现了INotifyPropertyChanged。此类具有一个属性: private DataTable totalsStatus = new DataTable(); public DataTable TotalsStatus { get { return totalsStatus; } set {

我对WPF/XAML完全陌生。我正在尝试编写XAML代码来将DataTable绑定到DataGrid。我有一个自定义DataContainer类的实例,它实现了INotifyPropertyChanged。此类具有一个属性:

private DataTable totalsStatus = new DataTable();
public DataTable TotalsStatus
{
    get { return totalsStatus; }
    set
    {
        totalsStatus = value;
        NotifyPropertyChanged("TotalsStatus");
    }
}
现在,在我的主窗口的C'tor中,我有这个,它像一个符咒:

Binding b = new Binding();
b.Source = DataContainer;
b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
b.Path = new PropertyPath("TotalsStatus");
DataGridMain.SetBinding(DataGrid.ItemsSourceProperty, b);
如何在XAML中创建此绑定?

您需要使用objectdataprovider

然后,您可以使用

<DataGrid ItemsSource="{Binding Source={StaticResource dtable}}" ></DataGrid>

不过,在xaml中进行绑定有不同的方法,所以请稍微玩玩一下。

在一天结束时,我决定用xaml实例化我的类,用代码隐藏的方式实例化FindResource,它使所有的代码更加清晰。我试图从这个问题中找出解决问题的方法:我在代码中尝试了这个方法,它的工作原理与我的DataGrid _gridData.ItemsSource=DataTablebase.ItemsSource.DefaultView的工作原理相同;但是,现在如何在C no XAML中以编程方式绑定DataGrid列?
<DataGrid ItemsSource="{Binding Source={StaticResource dtable}}" ></DataGrid>