Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Erro de navegação para a nova view criada.

Olá, boa tarde!

Estou tendo o mesmo problema. Aparece a mensagem de erro "Não é possível converter de 'App4.Views.ViewDetails' para 'Xamarin.Forms.Page'".

Este é o código da página existente CarList, onde temos a lista de veículos e o evento Navigation.PushAsync:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace App4.Views
{

    public class Veiculo
    {
        public string Nome { get; set; }
        public decimal Preco { get; set; }
        public string PrecoFormatado
        {
            get { return string.Format("R$ {0}", Preco); }
        }
    }

    public partial class CarList: ContentPage
    {
        public List<Veiculo> Veiculos { get; set; }

        public CarList()
        {
            InitializeComponent();

            this.Veiculos = new List<Veiculo>
            {
                new Veiculo {Nome = "Mercedez Bens", Preco = 75000},
                new Veiculo {Nome = "Mazda Accuraci", Preco = 80000},
                new Veiculo {Nome = "Land Rover", Preco = 90000}
            };

            this.BindingContext = this;
        }

        private void ListViewVeiculos_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            var veiculo = (Veiculo)e.Item;

            Navigation.PushAsync(new ViewDetails());
        }
    }
}

Este é o código da pagina App, onde já incluí o new NavigationPage:

using App4.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xamarin.Forms;

namespace App4
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();

            MainPage = new NavigationPage(new CarList());
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}

O cabeçalho da pagina ViewDetails():

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App4.Views.ViewDetails">
  <ContentView.Content>
      <StackLayout>
          <Label Text="Hello Xamarin.Forms!" />
      </StackLayout>
  </ContentView.Content>
</ContentView>

Como resolve este problema?

1 resposta
solução!

Seu ViewDetails tem que ser uma ContentPage e não uma ContentView. ContentView é para criar componentes / Elementos de Tela(Page)

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software