Tentei para Windows Phone e funciona quando compilo. Porém para android ele apresenta o seguinte erro: System.MissingMethodException: Method 'Android.Support.V4.Widget.DrawerLayout.AddDrawerListener' not found.
//App
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace AluraNutricao
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new AluraNutricao.CadastraRefeicao());
}
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
}
}
}
//ListaRefeicoes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace AluraNutricao
{
public partial class ListaRefeicoes : ContentPage
{
public ListaRefeicoes()
{
InitializeComponent();
}
}
}
//ListaRefeicoesXML
<?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="AluraNutricao.ListaRefeicoes">
<StackLayout>
<Label text="TelaDeListaRefeicoes"/>
</StackLayout>
</ContentPage>
//CadastraRefeicao
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace AluraNutricao
{
public partial class CadastraRefeicao : ContentPage
{
public CadastraRefeicao()
{
InitializeComponent();
}
public void AtualizaContador(Object sender, EventArgs e)
{
double calorias = sldCalorias.Value;
lblTextCalorias.Text = calorias.ToString();
}
public void SalvaRefeicao(Object sender, EventArgs e)
{
string descricao = entDescricao.Text;
double valor = sldCalorias.Value;
string msg = "A refeição " + descricao + " foi salva com " + valor.ToString() + " calorias";
DisplayAlert("Salvar Refeição", msg, "OK");
this.Clear();
}
public void MostraLista(Object sender, EventArgs e)
{
ListaRefeicoes tela = new ListaRefeicoes();
Navigation.PushAsync(tela);
}
public void Clear()
{
entDescricao.Text = "";
sldCalorias.Value = 0;
}
}
}
//CadastraRefeicaoXML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:AluraNutricao"
x:Class="AluraNutricao.CadastraRefeicao">
<StackLayout>
<Label Text="Cadastro de Refeição"/>
<Label Text="Descrição"/>
<Entry x:Name="entDescricao" Placeholder="Ex: File de Frango"/>
<Label Text="Calorias"/>
<Label Text="10" x:Name="lblTextCalorias"/>
<Slider x:Name="sldCalorias" Minimum="0" Maximum="1000" ValueChanged="AtualizaContador"/>
<Button Text="Salvar" Clicked="SalvaRefeicao"/>
<Button Text="Abrir Lista" Clicked="MostraLista"/>
</StackLayout>
</ContentPage>