我正在尝试将 dataGrid 与 ObservableCollection 的某些元素绑定,但我的问题是当我向 dataGrid 添加一行时,会显示 ObservableCollection 的所有属性
这是我添加行之前的dataGrid图片:
这是添加了行的 dataGrid 的图片:
如您所见,列已添加到数据网格中
视图的xml:
查看型号:
public EntreeDeCommandeViewModel(IBanniereService banniereService
, IItemsFactureService itemsFactureService
, IFactureService factureService, INavigationService navigationService)
{
_banniereService = banniereService;
_navigationService = navigationService;
_itemsFactureService = itemsFactureService;
_factureService = factureService;
RetrieveArgs = new RetrieveArticleFactureArgs();
AjouterItem = new RelayCommand(() =>
{
List<ItemsFacture> _itFacture = new List<ItemsFacture>();
_itFacture.Add(new ItemsFacture() {NombreArticle = RetrieveArgs.NombreArticle
, PrixUnitaireArticle = RetrieveArgs.PrixArticle
, PrixTotalArticle = (RetrieveArgs.NombreArticle * RetrieveArgs.PrixArticle) });
ItemsFactures = new ObservableCollection<ItemsFacture>(_itFacture);
});
}
public RetrieveArticleFactureArgs RetrieveArgs {get; set;}
private ObservableCollection<ItemsFacture> _itemsFacture;
public ObservableCollection<ItemsFacture> ItemsFactures
{
get
{
return _itemsFacture;
}
set
{
if (_itemsFacture == value)
{
return;
}
RaisePropertyChanging();
_itemsFacture = value;
RaisePropertyChanged();
}
}
班上 :
public class ItemsFacture : ObservableObject
{
#region Membre
private int? _idItemsFacture = null;
private Facture _facture;
private Article _article;
private int? _nombreArticle;
private double _prixUnitaireArticle;
private double _prixTotalArticle;
#endregion
#region Propriete ItemsFacture
public virtual int? IdItemsFacture
{
get
{
return _idItemsFacture;
}
set
{
if (_idItemsFacture == value)
{
return;
}
RaisePropertyChanging();
_idItemsFacture = value;
RaisePropertyChanged();
}
}
public virtual Facture Facture
{
get
{
return _facture;
}
set
{
if (_facture == value)
{
return;
}
RaisePropertyChanging();
_facture = value;
RaisePropertyChanged();
}
}
public virtual Article Article
{
get
{
return _article;
}
set
{
if (_article == value)
{
return;
}
RaisePropertyChanging();
_article = value;
RaisePropertyChanged();
}
}
public virtual int? NombreArticle
{
get
{
return _nombreArticle;
}
set
{
if (_nombreArticle == value)
{
return;
}
RaisePropertyChanging();
_nombreArticle = value;
RaisePropertyChanged();
}
}
public virtual double PrixUnitaireArticle
{
get
{
return _prixUnitaireArticle;
}
set
{
if (_prixUnitaireArticle == value)
{
return;
}
RaisePropertyChanging();
_prixUnitaireArticle = value;
RaisePropertyChanged();
}
}
public virtual double PrixTotalArticle
{
get
{
return _prixTotalArticle;
}
set
{
if (_prixTotalArticle == value)
{
return;
}
RaisePropertyChanging();
_prixTotalArticle = value;
RaisePropertyChanged();
}
}
#endregion
}