Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

Criando nova View

Criei o arquivo DetalheView esta dando erro, informando que "não é possivel converter de "App_foto.Views.DetalheView" para "Xamarin.Forms.Page" - Erro no arquivo ListagemView.xaml.cs

        private void ListViewClientes_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            var cliente = (Cliente)e.Item;

            Navigation.PushAsync(new DetalheView());

        }

No new DetalheView() esta apontando erro.

4 respostas

Luiz, você pode postar o cabeçalho dos arquivos DetalheView.xaml e DetalheView.xaml.cs para verificarmos? Obrigado

Bom dia, desculpa a demora, segue os códigos.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App_foto.Views.DetalheView">
</ContentPage>

outro arquivo

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

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace App_foto.Views
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class DetalheView : ContentPage
    {
        public DetalheView ()
        {
            InitializeComponent ();
        }
    }
}
solução!

Olá, Luiz!

Verifique o código da sua classe App.xaml.cs. Como você está usando navegação com Navigation.PushAsync, você deve definir o início da navegação com um NavigationPage, assim:

        public App()
        {
            InitializeComponent();

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

Boa sorte e bons estudos!

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?

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