我在一个视图模型中有一个类对象。我想将此对象状态传递给MVVM中的另一个View Model

时间:2014-10-16 20:45:35

标签: silverlight mvvm

在AttachmentViewModel中,我有以下代码

public ICommand EditAttachmentCommand { get; private set; }

public AttachmentsViewModel()
{
    EditAttachmentCommand = new ActionCommand<AvailAttachment>(EditAttachment);
}
private void EditAttachment(AvailAttachment attachment)
{
    var attachmentDetailsViewModel = Router.ResolveViewModel<AttachmentDetailsViewModel>(true,            ViewModelTags.ATTACHMENT_DETAILS_VIEWMODEL);
    attachmentDetailsViewModel.NavigateToAttachment(attachment.ArticleId);
    EventAggregator.Publish(ViewTags.ATTACHMENT_DETAILS_VIEW.AsViewNavigationArgs());
    EventAggregator.Publish(new CurrentViewMessage(ContentView.Attachment));
}       

在我的MainViewModel中,我有以下代码:

public ICommand SessionAttachmentCommand { get; private set; }
public MainMenuViewModel()
{
    SessionAttachmentCommand = new ActionCommand<AvailAttachment>(EditAttachment);
}

private void EditAttachment(AvailAttachment attachment)
{
    var attachmentDetailsViewModel = Router.ResolveViewModel<AttachmentDetailsViewModel>(true, ViewModelTags.ATTACHMENT_DETAILS_VIEWMODEL);
    attachmentDetailsViewModel.NavigateToAttachment(attachment.ArticleId);       
    EventAggregator.Publish(ViewTags.ATTACHMENT_DETAILS_VIEW.AsViewNavigationArgs());
    EventAggregator.Publish(new CurrentViewMessage(ContentView.Attachment));
}

我想将AvailAttachment类的对象状态从AttachmentsViewModel传递给MainMenuViewModel。目前,在MainMenuViewModel中,AvailAttachment的附件对象为null值。我正在调试某人编写的代码。这是一个使用MVVM模型的Silverlight项目。我该怎么做?

感谢任何帮助。感谢

0 个答案:

没有答案