[英]How to bind a datatable inside an object to a datagrid in XAML?
I have a viewmodelclass, inside which a datatable is a part of another model class. 我有一个viewmodelclass,在其中一个数据表是另一个模型类的一部分。 I want to bind it to the datagrid in XAML. 我想将其绑定到XAML中的datagrid。 I have just started to learn MVVM. 我刚刚开始学习MVVM。 Any help would be appreciated. 任何帮助,将不胜感激。
My Model Class: 我的模特班:
public class AllResultsModel
{
private DataTable _allresultsgrid;
private int _numberofrows;
public DataTable AllResultsGrid
{
get { return _allresultsgrid; }
set { _allresultsgrid = value; }
}
public int NumberOfRows
{
get { return _numberofrows; }
set { _numberofrows = value; }
}
}
ViewModel.cs: ViewModel.cs:
private AllResultsModel _allresultstable;
public AllResultsModel AllResultsTable
{
get { return _allresultstable; }
set
{
_allresultstable = value;
}
}
XAML: XAML:
<DataGrid Name="results_grid" IsReadOnly="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="10" ItemsSource="{Binding AllResultsTable}" DisplayMemberPath="AllResultsGrid" ColumnWidth="100" RowHeight="30">
I want to bind the Allresultsgrid in Allresultsmodel to the datagrid. 我想将Allresultsmodel中的Allresultsgrid绑定到数据网格。
You can bind property same as we are accessing objects inside a class using [ClassName].[ObjectName]. 您可以使用[ClassName]。[ObjectName]绑定与访问类内部对象相同的属性。 Here you can achieve as mentioned below. 在这里您可以实现如下所述。
<DataGrid Name="results_grid" IsReadOnly="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Margin="10" ItemsSource="{Binding AllResultsTable.AllResultsGrid}" DisplayMemberPath="AllResultsGrid" ColumnWidth="100" RowHeight="30">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.