将参数(如客户ID)传递给viewmodel的构造函数的一些推荐方法是什么?
编辑:
每个viewmodel所需的参数不是在模型之间共享的.它是每个viewmodel实例独有的.
//Create a container class to pass via messenger service public class CarSelectedArgs { #region Declarations public Car Car { get; set; } #endregion #region Constructor public CarSelectedArgs(Car car) { Car = car; } #endregion } //example of vIEw model sending message. public class Sendingviewmodel : viewmodelBase { private Car _car; public Car SelectedCar { get { return _car; } set { _car = value; if (value != null) { //messenger will notify all classes that have registered for a message of this type Messenger.Default.Send(new CarSelectedArgs(value)); } } } } //Example of viewmodel registering to recIEve a message public class Sampleviewmodel : viewmodelBase { #region Constructor public Sampleviewmodel() { Messenger.Default.Register<CarSelectedArgs>(this,OnCarSelected); } #endregion #region LocalMethods voID OnCarSelected(CarSelectedArgs e) { var NewCar = e.Car; } #endregion }总结
以上是内存溢出为你收集整理的silverlight – MVVM:如何将参数传递给ViewModel的构造函数全部内容,希望文章能够帮你解决silverlight – MVVM:如何将参数传递给ViewModel的构造函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)