参考 N=9 我想做的是代替 ILocationService 我有自己的 INavigationService 和导航服务类。
public class NavigationService :INavigationService
{
private readonly IMvxMessenger _navigator;
public NavigationService(IMvxMessenger navigator)
{
_navigator = navigator;
}
public void OnNavigation(PurchasesDataEntryViewModel vm)
{
var navigationMessage = new NavigationMessage(this,vm);
_navigator.Publish(navigationMessage);
}
}
这是我的 Messenger 课程:
public class NavigationMessage : MvxMessage
{
public string ShopID { private set; get; }
public int TotalStock { private set; get; }
public int TotalPurchases { private set; get; }
public int Stock1 { private set; get; }
public int Stock2 { private set; get; }
public int Stock3 { private set; get; }
public int Purch1 { private set; get; }
public int Purch2 { private set; get; }
public int Purch3 { private set; get; }
public string Name { private set; get; }
public string CPrice { private set; get; }
public int CSales { private set; get; }
public string BrandID { private set; get; }
public string CatID { private set; get; }
public int LadgePur { private set; get; }
public decimal LPrice { private set; get; }
public int LPurch { private set; get; }
public int LSales { private set; get; }
public int LStock { private set; get; }
public int LStock1 { private set; get; }
public string MeasureID { private set; get; }
public NavigationMessage(object sender, PurchasesDataEntryViewModel vm)
: base(sender)
{
ShopID = vm.ShopID;
TotalStock = vm.TotalStock;
TotalPurchases = vm.TotalPurchases;
Stock1 = vm.Stock1;
Stock2 = vm.Stock2;
Stock3 = vm.Stock3;
//Purch1 = vm.Purch1;
//Purch2 = vm.Purch2;
//Purch3 = vm.Purch3;
Name = vm.Name;
CPrice = vm.CPrice;
// CSales = vm.CSales;
BrandID = vm.BrandID;
CatID = vm.CatID;
LadgePur = vm.LadgePur;
LPrice = vm.LPrice;
LPurch = vm.LPurch;
LSales = vm.LSales;
LStock = vm.LStock;
LStock1 = vm.LStock1;
MeasureID = vm.MeasureID;
}
我想要实现的是将上述值发送给我的订阅者 PurchasesDataEntryViewModel
private readonly IDataService _dataService;
private readonly MvxSubscriptionToken _token;
public PurchasesDataEntryViewModel(IDataService dataService,INavigationService service, IMvxMessenger navigator)
{
_dataService = dataService;
_token = navigator.Subscribe<NavigationMessage>(OnNavigationMessage);
}
private void OnNavigationMessage(NavigationMessage navigationMessage)
{
ShopID = navigationMessage.ShopID;
.
.
.
}
}
我无法让它工作。我需要了解发布/订阅的交互和生命周期。两个视图模型将如何理解如何通信。我需要以某种方式告诉我的 Messenger 服务,我想通过 Messenger 类将参数从 ViewModel A 发送到 ViewModel B。这是我第一次使用该插件,所以请原谅我的愚蠢问题。