1 回答
![?](http://img1.sycdn.imooc.com/533e4c0500010c7602000200-100-100.jpg)
TA贡献1844条经验 获得超8个赞
您可以使用 CartViewModel 作为参数:
public POSViewModel()
{
CartViewModel = new CartViewModel();
ProductsViewModel = new ProductsViewModel(CartViewModel);
}
并在 ProductsViewModel 的构造函数中使用它
public class ProductsViewModel : Conductor<object>
{
public BindableCollection<ProductModel> Products { get; set; }
public CartViewModel CVM { get; set; }
public ProductsViewModel(CartViewModel CVM)
{
this.CVM = CVM;
}
public void AddProdClick(ProductModel productModel)
{
CVM.Add(productModel)
}
}
您还有另一个解决方案:使用 PosViewModel:
public POSViewModel()
{
CartViewModel = new CartViewModel();
ProductsViewModel = new ProductsViewModel(this);
}
public class ProductsViewModel : Conductor<object>
{
public BindableCollection<ProductModel> Products { get; set; }
public CartViewModel CVM { get; set; }
public ProductsViewModel(POSViewModel PVM)
{
this.CVM = PVM.CartViewModel;
}
public void AddProdClick(ProductModel productModel)
{
CVM.Add(productModel)
}
}
第三种解决方案是使用EventAggregator,您需要修改一些编码
请参阅事件聚合器
单击时,您在 Add 方法中执行 EventAggregator.publish(new Addevent)
在 PosviewModel 中你可以捕捉到事件......
但为此你必须修改一些代码行,但阅读链接并不复杂
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报