简体   繁体   English

在WPF DataGrid上进行双重绑定?

[英]Double binding on a WPF DataGrid?

I am new to mvvm and I am not really familiar with the control DataGrid. 我是mvvm的新手,我对控件DataGrid并不是很熟悉。 I would like to known if we can do multiple binding on a DataGrid or anything. 我想知道我们是否可以对DataGrid或其他任何东西进行多重绑定。

Let me explain, I have 3 TextBox ( ProductName, Quantity, Price ) and i have 4 colums in my dataGrid ( ProductName, Quantity, Price, Total(price*quantity)). 让我解释一下,我有3个TextBox(ProductName,Quantity,Price),我的dataGrid中有4个列(ProductName,Quantity,Price,Total(price * quantity))。 I also have 2 bouton, (add product) which will add the textBox value to the DataGrid and a bouton (save) which will save the content of the dataGrid in a DataBase. 我也有2个bouton(添加产品),它将文本框值添加到DataGrid中;还有一个bouton(保存),它将数据网格中的内容保存在数据库中。

How should I proceed ? 我应该如何进行?

The DataSource of the DataGrid should point to a collection of items. DataGrid的DataSource应该指向项目的集合。

Each row will be a single entity of your collection and it's properties can then be bound to a column (using templates). 每行将是您集合的单个实体,然后可以将其属性绑定到一列(使用模板)。

See: Datagrid binding in WPF 请参阅: WPF中的Datagrid绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM