Xamarin.Forms Navigation.PushAsync不起作用 [英] Xamarin.Forms Navigation.PushAsync Not Working

查看:365
本文介绍了Xamarin.Forms Navigation.PushAsync不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Xamarin.Forms项目,我有一个自定义控件,在点击该控件时应打开一个新页面.不幸的是,当我呼叫Navigation.PushAsync(...);时,什么也没有发生.我已经阅读了无数StackOverflow问题(这样的)和Xamarin论坛进行了几次Google搜索,但似乎没有一个解决方案可以解决我的问题.

I have a Xamarin.Forms project, and I have a custom control that should open a new page when tapped. Unfortunately, nothing happens when I call Navigation.PushAsync(...);. I've read countless StackOverflow questions (such as this one) and Xamarin Forums threads and done several Google searches, but none of the solutions seem to solve my issue.

  • 我的控件继承自ContentView,因为所有Xamarin.Forms视图 做.
  • src是一个自定义类,其中包含一些数据点,这些数据点 由此控件和EventDetailsPage使用.
  • 我可以确认手势可以正常工作,但是对PushAsync()的调用没有任何作用.
  • 我尝试以某种方式操纵该语句,以便使用NavigationPage(这样它就变成myNavigationPage.Navigation.PushAsync(new EventDetailsPage(src));).
  • 我还尝试过创建一个构造器,该构造器采用Page并与上述要点类似地使用它.
  • My control inherits from ContentView, as all Xamarin.Forms views do.
  • src is a custom class that contains some data points that are used by this control and EventDetailsPage.
  • I can confirm that the gesture does work itself, but the call to PushAsync() does nothing.
  • I have tried manipulating the statement in ways so that a NavigationPage is used (such that it becomes myNavigationPage.Navigation.PushAsync(new EventDetailsPage(src));).
  • I have also tried creating a constructor that takes a Page and uses it in away similar to the above point.

我的控件的构造函数:

public EventControl() {
    InitializeComponent();
    GestureRecognizers.Add(new TapGestureRecognizer() {
        Command = new Command(() => Navigation.PushAsync(new EventDetailsPage(src)))
    });
}

通常,在我没有尝试解决其他问题的情况下,在StackOverflow上问一个新问题是我的最后选择.感谢您的帮助.

Typically, asking a new question on StackOverflow is my last resort when nothing else that I've tried solved my problem. Any help is appreciated.

推荐答案

我发现了问题. 基思·罗马(Keith Rome)带领我浏览EventDetailsPage,我评论了一行XAML,就解决了这个问题.该行正在向页面添加自定义控件(与EventControl不相关).我不知道控件的定义或其自定义渲染的定义是否引起了奇怪的行为,但是删除该行解决了此问题.

I found the problem. Keith Rome lead me to look through EventDetailsPage and I commented out a line of XAML, and that solved the problem. That line was adding a custom control to the page (not related to EventControl). I don't know if the control's definition or its custom render's definition was causing the strange behavior, but removing that line solved the issue.

这篇关于Xamarin.Forms Navigation.PushAsync不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆