我一直在阅读Laurent Bugnion的文章,以便我能理解mvvm。让我困惑的一件事就是如何在点击按钮时导航。 Laurent谈到Viewmodel和视图,但是如果按下按钮我是如何导航到另一个页面的呢?
视图模型
public class HomeViewModel : ViewModelBase {
private readonly INavigationService _navigationService;
private RelayCommand _navigateCommand;
private LibraryViewModel _libraryView;
public LibraryViewModel LibraryView {
get { return _libraryView; }
set { _navigationService.Navigate(typeof(LibraryPage)); }
}
...
}
查看
<AppBarButton
x:Uid="LibraryButton"
Command="{Binding LibraryView, Mode=TwoWay}"
Icon="List"/>