我对mvvm和mvvm light还比较陌生,但我认为我理解了它的一般思想。 我不明白的是,如果我想打开一个新窗口,但是该窗口需要来自调用者的数据,那么最好的做法是什么? 如果我将数据传递给构造函数,那么这意味着我需要在代码后台中编写代码将其传递给视图模型。 我不能使用消息传递,因为它不是基本数据。
我对mvvm和mvvm light还比较陌生,但我认为我理解了它的一般思想。 我不明白的是,如果我想打开一个新窗口,但是该窗口需要来自调用者的数据,那么最好的做法是什么? 如果我将数据传递给构造函数,那么这意味着我需要在代码后台中编写代码将其传递给视图模型。 我不能使用消息传递,因为它不是基本数据。
public class DialogService : IDisposable
{
#region Member Variables
private static volatile DialogService instance;
private static object syncroot = new object();
#endregion
#region Ctr
private DialogService()
{
}
#endregion
#region Public Methods
public void ShowDialog(object _callerContentOne, object _callerContentTwo)
{
MyDialogViewModel viewmodel = new MyDialogViewModel(_callerContentOne, _callerContentTwo);
MyDialogView view = new MyDialogView();
view.DataContext = viewmodel;
view.ShowDialog();
}
#endregion
#region Private Methods
#endregion
#region Properties
public DialogService Instance
{
get
{
if (instance == null)
{
lock (syncroot)
{
if (instance == null)
{
instance = new DialogService();
}
}
}
return instance;
}
}
#endregion
}