关于 MVVM 模式的问题,我认为我错了。
当视图中发生触地事件时,我想弹出一条消息,即:
private void marker_TouchDown(MessageObject msgData)
{
CustomMessageControl message = new CustomMessageControl() {Width = 610, Height = 332};
CustomMessageViewModel messageVM = new CustomMessageViewModel(msgData);
message.DataContext = messageVM;
//Add to canvas
}
我的视图模型:
public class CustomMessageViewModel
{
public MessageObject message { get; set; }
public CustomMessageViewModel(MessageObject message)
{
this.MessageObject = message;
}
}
这有效,但感觉不对。这是填充视图模型的可接受方式吗?