关闭ViewModel时,Xamarin形成MVVMCROSS如何传递参数

发布于 2025-02-02 19:44:49 字数 1153 浏览 1 评论 0原文

我使用MVVMCROSS有Xamarin形式。我的视图模型之一加载了一个新的ViewModel:

 public class ViewModelMainForm: BaseViewModel, IMvxViewModel<string>
     {
    
..... some code here .....

public void Prepare(String parameters)
        {
           // should get incidentId HERE****
            
        }

public async void OnShowIncidentForm()
    {
        var result = await _navigation.Navigate(typeof(ViewModelIncidentForm), _selectedItem.EmployeeId);
    }
}

然后,新视图看起来很完美,我可以在准备方法中接收员工。

 public class ViewModelIncidentForm : BaseViewModel, IMvxViewModel<string>
 {

   ..... some code here .....

      public void Prepare(String parameters)
        {
           
            employeeId = parameters.ToString();

            GetEmployeeData(employeeId);

        }

     public void CloseView(int incidentId)
     {

        _navigation.Close(this, incidentId);
     }

 }

所有这些都可以完美,问题在于,当我关闭视图模型以弹出到上一个ViewModel时,我不知道如何获取参数“ InventiDID>”。

在我的主要形式ViewModel中,我已经在准备方法中放置了一个断点,但没有触发。

关于如何在我的主ViewModel中使用navigation.close()方法中发送的参数的任何线索?

I have a Xamarin Forms using MVVMCross. One of my view models loads a new ViewModel like this:

 public class ViewModelMainForm: BaseViewModel, IMvxViewModel<string>
     {
    
..... some code here .....

public void Prepare(String parameters)
        {
           // should get incidentId HERE****
            
        }

public async void OnShowIncidentForm()
    {
        var result = await _navigation.Navigate(typeof(ViewModelIncidentForm), _selectedItem.EmployeeId);
    }
}

Then the new view appears perfect and I can receive the EmployeeId in the Prepare method.

 public class ViewModelIncidentForm : BaseViewModel, IMvxViewModel<string>
 {

   ..... some code here .....

      public void Prepare(String parameters)
        {
           
            employeeId = parameters.ToString();

            GetEmployeeData(employeeId);

        }

     public void CloseView(int incidentId)
     {

        _navigation.Close(this, incidentId);
     }

 }

All this works perfect, the problem is that when I close the ViewModel to pop to the previous ViewModel I don't know how to get the parameter "incidentId".

In my main form ViewModel, I already placed a breakpoint into the Prepare method but is not triggered.

Any clue on how to get the parameter sent in the navigation.Close() method in my main ViewModel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文