2011-08-17 46 views
0

修改这是我收集:WPF observablecollection。从子窗口

public ObservableCollection<CheckOutData> _CheckOutCollection = new ObservableCollection<CheckOutData>(); 
     public ObservableCollection<CheckOutData> CheckOutCollection 
      { 
       get { return _CheckOutCollection; } 
      } 

      public class CheckOutData 
      { 
       public int ID { get; set; } 
       public string RoomType { get; set; } 
       public string RoomNumber { get; set; } 
       public decimal RoomPrice { get; set; } 
       public string RoomPriceWithCurrency { get; set; } 
       public decimal Discount { get; set; } 
       public decimal DiscountedPrice { get; set; } 
       public string DiscountedPriceWithCurrency { get; set; } 
       public string CheckIn { get; set; } 
       public string CheckOut { get; set; } 
       public int TotalDay { get; set; } 
       public string CheckOutHour { get; set; } 
     } 

我有另外一个窗口,在这里我想要做以下操作:添加CheckOutData公共字符串服务名{获得;设置} 怎么能这样做呢?我甚至不会在我的子窗口中看到checkoutdata。 所以我的主要任务是在checkoutdata中添加新的集合,然后重新绑定datagrid。谁能帮我?

private CheckOut m_parent;

public AddActionService(CheckOut parent) 
{ 
    InitializeComponent(); 
    m_parent = parent; 

} 

回答

1

您可能想要考虑某种事件聚合器。通过这种方式,任何表单的代码(或者ViewModel/Presenter,如果您使用MVVM/MVP)都可以发送由聚合器拾取并分发给订阅了该事件的任何其他表单/ ViewModels/Presenter的消息。这种方式意味着你的表格不再紧密地结合在一起。他们根本就没有互相参照。他们通过事件聚合器进行通信,他们甚至不知道是否有任何对象正在监听这些事件。

你也可以考虑采取更进一步的措施,并采用“域事件”风格,它允许您对这些事件做出反应,不仅在UI中,而且还在系统中其他位置的域对象中作出反应,包括通过调用Web服务的外部服务,更新数据库,将消息放入队列中等。