2011-08-17 45 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服務的外部服務,更新數據庫,將消息放入隊列中等。