0
我可以導航到DetailPage.xaml以顯示更多信息,但無法將對象傳遞給DetailVieModel,並且當我按下應用程序關閉按鈕時。使用MVVM Light在WP 8.1中導航
這裏是我的代碼:
在ViewModelLocator
public ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
var navigationService = this.CreateNavigationService();
SimpleIoc.Default.Register<INavigationService>(() => navigationService);
SimpleIoc.Default.Register<MainViewModel>();
SimpleIoc.Default.Register<DataService>();
SimpleIoc.Default.Register<DetailViewModel>(true);
}
的導航,我只有一個就目前而言,這似乎工作becouse我可以導航到DetailPage.xaml。
private INavigationService CreateNavigationService()
{
var navigationService = new NavigationService();
navigationService.Configure("DetailPage", typeof(DetailPage));
return navigationService;
}
這是我在MainViewModel做:
public RelayCommand ShowDetailPage
{
get
{
return new RelayCommand(() =>
{
_INavigationService.NavigateTo("DetailPage");
});
}
}
這是我想傳遞給DetailViewModel對象
private Info _SelectedObject;
public Info SelectedObject
{
get
{
return _SelectedObject;
}
set
{
_SelectedObject = value;
if (value != null)
{
Messenger.Default.Send<Info>(value);
_SelectedObject = null;
}
RaisePropertyChanged("SelectedObject");
}
}
這是我做的觸發命令on MainPage.xaml
<ListView Grid.Row="1"
ItemsSource="{Binding ObjectsList}">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Tapped">
<core:InvokeCommandAction Command="{Binding ShowDetailPage}"
CommandParameter="{Binding SelectedObject}" />
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
而finaly在DetailViewModel我要求與Messenger.Register的SelectedObject ...
Messenger.Default.Register<Info>(this, (selectedinfo) =>
{
_SelectedInfo = selectedinfo;
});
對象傳遞不起作用:/ – Bayern
如何檢索另一頁中傳遞的參數? –
啊嘿,我忘了註冊我的DetailViewModel ...現在一切正常,謝謝你! – Bayern