2
I’m having problems showing the contents of the pages. I created a Listview with some options, follow the code below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace testeVale.Views
{
public class Menu
{
public string itemMenu { get; set; }
}
public partial class MainPage : ContentPage
{
public List<Menu> Itens { get; set; }
public MainPage()
{
InitializeComponent();
this.Itens = new List<Menu>
{
new Menu { itemMenu = "Sobre Nós"},
new Menu { itemMenu = "Cidades" },
new Menu { itemMenu = "Eventos" },
new Menu { itemMenu = "Contato" }
};
this.BindingContext = this;
}
void ListViewMenu_ItemTapped(object sender, ItemTappedEventArgs e)
{
var menu = (Menu) e.Item;
if (menu.itemMenu is "Sobre Nós")
{
Navigation.PushAsync(new sobreNos(menu));
}
if (menu.itemMenu is "Contato")
{
Navigation.PushAsync(new contato(menu));
}
/*DisplayAlert("Menu", string.Format("Você tocou no modelo'{0}'", menu.itemMenu),"Fechar");*/
}
}
}
On the "About Us" page for example, I’m trying to display the content but it’s only showing the 'back' button'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace testeVale.Views
{
public partial class sobreNos : ContentPage
{
public sobreNos(Menu opcao)
{
InitializeComponent();
this.Title = opcao.itemMenu;
var label = new Label { Text = "This is a label." };
}
private void buttonVoltar_Clicked(object sender, EventArgs e)
{
Navigation.PushAsync(new MainPage());
}
}
}
I also tried the shampoo:
<?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="testeVale.Views.sobreNos">
<ContentPage.Content>
<StackLayout Padding="5,10">
<Label TextColor="#77d065" FontSize = "20" Text="Sobre Nós" />
</StackLayout>
</ContentPage.Content>
<Button x:Name="buttonVoltar" Text="Voltar" Clicked="buttonVoltar_Clicked" VerticalOptions="End"></Button>
</ContentPage>
Nothing appears, only the button, what I’m doing wrong?
I put inside the Stacklayout and appeared the content, what is the function of this command? Is similar to the Linearlayout of Android? Whenever I want to place content you will need to stay within this term?
– Ricardo Goncalves
The Stacklayout organizes your views (Buttons, Labels...) in a row of one dimension - either horizontal or vertical, one below the other or one beside the other. If you want the views to be in this layout, the most appropriate is to use the Stacklayout. I suggest a read on Layouts - Xamarin
– Armindo Gomes