Dra*_*gos 7 c# mvvm xamarin xamarin.forms
我有几个ContentPages,我想通过单击页面中的元素从一个导航到另一个.我有我的ViewModel类:
class JumpVM : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private INavigation _navigation;
public ICommand NewPage
{
get
{
return new Command(async () =>
{
await _navigation.PushAsync(new MySettingsPage());
});
}
}
public JumpVM() { }
public JumpVM(INavigation navitation)
{
_navigation = navitation;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的一个页面(为了空间,我只放了相关的代码):
BindingContext = new JumpVM(this.Navigation);
Run Code Online (Sandbox Code Playgroud)
....
Image fbInvite = new Image
{
Source = ImageSource.FromResource(Constants.ASSETLOCATION + ".facebookInviteIcon.png"),
HorizontalOptions = LayoutOptions.Center
};
fbInvite.GestureRecognizers.Add(new TapGestureRecognizer(sender =>
{
//navigation in the method below
FaceboonInviteFriends();
fbInvite.Opacity = 0.8;
fbInvite.FadeTo(1);
}));
Run Code Online (Sandbox Code Playgroud)
我想在单击图像时执行JumpVM类中的Command并导航到那里的页面.我怎样才能做到这一点?
小智 6
这是在ViewModel概念中将一页导航到另一页的答案。
public ICommand NavigationList { get; set; }
NavigationList = new Command(GetListview);
public void GetListview()
{
Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new ListViewPerson());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8709 次 |
| 最近记录: |