使用MVVM灯在接收视图中获取导航参数 [英] getting the navigated parameters in recepient view using MVVM light

查看:119
本文介绍了使用MVVM灯在接收视图中获取导航参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在页面上有一个按钮(MyPage.xaml)。单击该按钮,我导航到一个新页面(NewPage.xaml)。


这两个页​​面都有相同的viewmodel(MyViewModel.cs)。


使用Navigationservice实现导航  MVVM灯的工作正常。


从MyPage.xaml,我需要将employeeID传递给 新页面并基于此员工ID我需要在NewPage.xaml上显示数据。


我的问题是如何在加载事件中跟踪上一页的员工ID  NewPage .xaml。



我的代码片段如下:


MyPage.xaml:



< Button Content =" Create" &NBSP; X:名称= QUOT;&的BtnCreate QUOT;&NBSP; >

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; <交互:Interaction.Behaviors>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; <核心:EventTriggerBehavior事件名称= QUOT;按一下[;>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < core:InvokeCommandAction Command =" {Binding CreateCommand,Source = {StaticResource 
Locator}}"

              CommandParameter =" {Binding ElementName = MainContent}" />

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < /芯:EventTriggerBehavior>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; < /交互:Interaction.Behaviors>

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; < / Button>


MyViewModel.cs:


'p>&NBSP;私人INavigationService _navigationService;


&NBSP;公共无效创建(对象参数)

        {  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;   

                _navigationService.NavigateTo(" New",参数); 

        }


FrameNavigation.cs:


private static void SetupNavigation()

  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

            navigationService = new FrameNavigationService();

            navigationService.Configure(QUOT;最新及QUOT ;, typeof运算(新页));

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; SimpleIoc.Default.Register< INavigationService>(()=> navigationService);

        }



任何帮助都将受到高度赞赏。



先谢谢。

解决方案

ABC30,


>>"我的问题是如何在NewPage.xaml的加载事件中跟踪上一页中的员工ID"


如果你想要得到的参数值,你可以得到它在"OnNavigatedTo"处理程序方法而不是使用加载事件。

 protected override void OnNavigatedTo(NavigationEventArgs e)
{
var parameter = e.Parameter as string; //"您的数据"
base.OnNavigatedTo(e);
}

最好的问候,


Xavier Eoro



Hi,

I have a button on a page(MyPage.xaml). On the click of the button, I navigate to a new page(NewPage.xaml).

Both the pages have same viewmodel(MyViewModel.cs).

The navigation is implemented using Navigationservice  of MVVM light and is working fine.

From MyPage.xaml, I need to pass employeeID to the  new page and based on this employee Id I need to display data on NewPage.xaml.

My problem is how to track the employee id from the previous page on the Load Event of NewPage.xaml.

My code snippets are below:

MyPage.xaml:

<Button Content="Create"  x:Name="btnCreate"  >
                        <interactivity:Interaction.Behaviors>
                            <core:EventTriggerBehavior EventName="Click">
                                <core:InvokeCommandAction Command="{Binding CreateCommand,Source={StaticResource  Locator}}"
              CommandParameter="{Binding ElementName=MainContent}" />
                            </core:EventTriggerBehavior>
                        </interactivity:Interaction.Behaviors>
                    </Button>

MyViewModel.cs:

 private INavigationService _navigationService;

 public void Create(object parameter)
        {                           
                _navigationService.NavigateTo("New", parameter); 
        }

FrameNavigation.cs:

private static void SetupNavigation()
        {
            navigationService = new FrameNavigationService();
            navigationService.Configure("New", typeof(NewPage));
            SimpleIoc.Default.Register<INavigationService>(() => navigationService);
        }

Any help would be highly appreciated.

Thanks in Advance.

解决方案

Hi ABC30,

>>"My problem is how to track the employee id from the previous page on the Load Event of NewPage.xaml"

If you want to get the parameter value, you could get it on the "OnNavigatedTo" handler method instead of using the load event.

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var parameter = e.Parameter as string;  // "Your data"
        base.OnNavigatedTo(e);
    }

Best Regards,

Xavier Eoro


这篇关于使用MVVM灯在接收视图中获取导航参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆