【发布时间】:2016-12-10 03:22:23
【问题描述】:
我对@987654321@ 和here 有一个类似的问题
现已编辑问题以包含更多信息
我有一个 wpf c#(编辑解决方案,其中有 3 个项目。这些项目是一个名为 CH_CustomerOutlook 的项目,并引用了第二个项目 DAL 项目,第三个是 CustomLibrary End Edit)CH_CustomerOutlook 项目的主窗口正常这是一个 DataGrid,它有一个我自己的类型的公共可观察集合,称为 Outlooks
对于 CustomerOutlook 类(编辑在 DAL 项目中并且)我已经设置了 INotifyPropertyChanged 并在 NotifyPropertyChanged 方法的句柄中我想在主窗口中访问这个 Observable 集合 Outlooks 并在类方法中使用它来更新DataGrid 上的总计
任何帮助都会非常感谢
代码是
public partial class MainWindow : Window
{
public static ProjectSettings Settings = new ProjectSettings();
// define new observable collection for data grid
public static ObservableCollection<SysproDAL.CustomerOutlook> OutlookCol = new ObservableCollection<SysproDAL.CustomerOutlook>();
public MainWindow()
{
InitializeComponent();
Settings.SetFromFile(Settings);
}
~Customer Outlook 类代码是
public class CustomerOutlook: INotifyPropertyChanged
{
//For CustomerOutlook static non changing propetties
public string Status { get; set; }
//For Return Merchandise changing propetties
private DateTime entrydate;
public DateTime EntryDate { get { return this.entrydate; }
set
{
if(this.entrydate != value)
{
this.entrydate = value;
this.NotifyPropertyChanged("EntryDate");
}
} }
//more properties defines etc
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
this.Status = "u";
if (propName == "M1")
{
//Want to Access public observable collection "Outlooks" from main Window
//The call method UpdateTotals (Outlooks);
}
}
}
public static void UpdateTotals(ObservableCollection<CustomerOutlook> Col)
{
var item = Col.FirstOrDefault(i => i.Status == "T");
if (item != null)
{
item.M1 = Col.Sum(x => x.M1);
item.M2 = Col.Sum(x => x.M2);
item.M3 = Col.Sum(x => x.M3);
}
}
【问题讨论】:
-
所以当您的
List中的一个项目在其NotifyPropertyChanged中发生更改时,您希望访问您的List?