1 回答

TA貢獻(xiàn)1844條經(jīng)驗(yàn) 獲得超8個贊
您可以使用 CartViewModel 作為參數(shù):
public POSViewModel()
{
CartViewModel = new CartViewModel();
ProductsViewModel = new ProductsViewModel(CartViewModel);
}
并在 ProductsViewModel 的構(gòu)造函數(shù)中使用它
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,您需要修改一些編碼
請參閱事件聚合器
單擊時(shí),您在 Add 方法中執(zhí)行 EventAggregator.publish(new Addevent)
在 PosviewModel 中你可以捕捉到事件......
但為此你必須修改一些代碼行,但閱讀鏈接并不復(fù)雜
- 1 回答
- 0 關(guān)注
- 116 瀏覽
添加回答
舉報(bào)