Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用wp 8.1中的mvvvm在导航页面之间传递数据?_C#_Mvvm_Windows Phone 8.1_Mvvm Light - Fatal编程技术网

C# 如何使用wp 8.1中的mvvvm在导航页面之间传递数据?

C# 如何使用wp 8.1中的mvvvm在导航页面之间传递数据?,c#,mvvm,windows-phone-8.1,mvvm-light,C#,Mvvm,Windows Phone 8.1,Mvvm Light,我不熟悉windows phone 8.1。我有一个视图列表,当用户单击某个项目时,他应该移动到该项目的“项目详细信息”页面,结果在视图模型I中绑定了一个执行以下操作的命令: ((Frame)Window.Current.Content).Navigate(typeof(ItemView), item); 到目前为止,一切都很顺利。但是如何在item details页面的视图模型中接收item对象 我可以在代码隐藏中访问它,但是解决这个问题的mvvm最佳实践是什么 假设您有以下列表。我遗漏了

我不熟悉windows phone 8.1。我有一个视图列表,当用户单击某个项目时,他应该移动到该项目的“项目详细信息”页面,结果在视图模型I中绑定了一个执行以下操作的命令:

 ((Frame)Window.Current.Content).Navigate(typeof(ItemView), item);
到目前为止,一切都很顺利。但是如何在item details页面的视图模型中接收item对象


我可以在代码隐藏中访问它,但是解决这个问题的mvvm最佳实践是什么

假设您有以下列表。我遗漏了项模板和项源的声明:

<ListView IsItemClickEnabled="True" x:Name="lvItems">
    <Interactivity:Interaction.Behaviors>
        <Core:EventTriggerBehavior EventName="ItemClick">
            <Core:InvokeCommandAction Command="{Binding NavigateDetailsCommand, Mode=OneWay}" InputConverter="{StaticResource ItemClickConverter}" CommandParameter="{Binding SelectedItem, ElementName=lvItems}"/>
        </Core:EventTriggerBehavior>
    </Interactivity:Interaction.Behaviors>
</ListView>
最后一件事是viewmodel,其中您将所有内容传递给一个命令:

public RelayCommand<MyEntity> NavigateDetailsCommand;

// In your constructor, do this:
this.NavigateDetailsCommand= new RelayCommand<MyEntity>(navigateDetails);
// I'm assuming you injected a navigation service into your viewmodel..
this._navigationService.Configure("itemviewpage", typeof(ItemView));


// Declare a method that does the navigation:
private void navigateDetails(MyEntity item) {
    this._navigationService.NavigateTo("itemviewpage", item);
}
public relay命令导航的tails命令;
//在构造函数中,执行以下操作:
this.navigateDetails命令=新的RelayCommand(navigateDetails);
//我假设您在viewmodel中注入了导航服务。。
这个.u navigationService.Configure(“itemviewpage”,typeof(ItemView));
//声明执行导航的方法:
私有void导航详细信息(MyEntity项){
此._navigationService.NavigateTo(“itemviewpage”,item);
}
public RelayCommand<MyEntity> NavigateDetailsCommand;

// In your constructor, do this:
this.NavigateDetailsCommand= new RelayCommand<MyEntity>(navigateDetails);
// I'm assuming you injected a navigation service into your viewmodel..
this._navigationService.Configure("itemviewpage", typeof(ItemView));


// Declare a method that does the navigation:
private void navigateDetails(MyEntity item) {
    this._navigationService.NavigateTo("itemviewpage", item);
}