Xamarin ToolBarItem点击事件而非重定向页面
这是MyCode
.xamal
<ContentPage.ToolbarItems>
<ToolbarItem Name="MenuItem1" Command="{Binding HomeMenuCommand}" Order="Primary" Icon="tab_home.png.png" Text="Home" Priority="0" />
</ContentPage.ToolbarItems>
视图模型
public ICommand HomeMenuCommand { get; }
public AboutViewModel()
{
Title = "About";
HomeMenuCommand = new Command(async () => await GoToHomeCommand());
}
async Task GoToHomeCommand()
{
await this.PushPageFromCacheAsync<MainViewModel>();
}
此页面位于TopOf标签页上,我使用Xamvvm查看模型绑定
当我把
await Application.Current.MainPage.DisplayAlert("test...", "test", "OK");
在GoToHomeCommand()消息内,Alert生成
请帮我解决
答案 0 :(得分:0)
虽然我没有尝试过Xamvvm,但看着你的问题,看来你的命令工作正常。唯一的问题是重定向。
你试过这个吗?
async Application.MainPage.Current = new NavigationPage(new YourPage());