WPF observablecollection.从子窗口修改

本文关键字:窗口 修改 observablecollection WPF | 更新日期: 2023-09-27 18:05:44

这是我的收藏:

   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公共字符串serviceName{get;set}如何做到这一点呢?我甚至没有在子窗口中看到checkout数据。所以我的主要任务是在checkoutdata中添加新的集合,然后重新绑定datagrid。有人能帮我吗?

private CheckOut m_parent;

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

WPF observablecollection.从子窗口修改

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

你还可以考虑更进一步,采用"域事件"风格,允许你不仅在ui中对这些事件做出反应,还可以在系统中其他地方的域对象中做出反应,包括通过外部服务发送消息来调用web服务,更新数据库,将消息放入队列等。