首页 > 解决方案 > I cannot call another screen when I click on the image

问题描述

I have two images to simulate the click on the button, but I want is when clicking the image and change call another screen. And the process does not happen because the application is stopping

<StackLayout>
        <!-- Place new controls here -->
        <Image Source="botaocadastrolivre.png">
        <Image.GestureRecognizers>
            <TapGestureRecognizer
                Tapped="OnTapGestureRecognizerTapped"
                NumberOfTapsRequired="1" />
        </Image.GestureRecognizers>
        </Image>
    </StackLayout>




void  OnTapGestureRecognizerTapped(object sender, EventArgs args)
        {
            tapCount++;
            var imageSender = (Image)sender;
            // watch the monkey go from color to black&white!
            if (tapCount % 2 == 0)
            {
                imageSender.Source = "botaocadastrolivre.png";
            }
            else
            {
                imageSender.Source = "botaocadastroPresed.png";
                Navigation.PushAsync(new Nova());
            }
           // Task.Delay(100)
           //Navigation.PushAsync(new Nova());
        }

标签: xamlxamarinxamarin.forms

解决方案


转到您的App.xaml.cs文件,找到类似以下内容的行:

MainPage = new MainPage();

并将其更改为:

MainPage = new NavigationPage(new MainPage());

这会将您的页面包装到导航页面中,然后该Navigation对象将知道如何从一个页面导航到另一个页面。

阅读 Xamarin.Forms 中的导航概念可能是明智之举:https ://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/


推荐阅读