I'm creating a little app to Win. Phone 8.1, that the user select a number of checkboxes, then, the app does a Foreach to verify which checkbox is selected, then the app gets the checkboxes content (text), fills a <list>
and send the list to another page, and in the page 2, fill a listview control.
Page 1
List<ClassDados> lista = new List<ClassDados>();
ClassDados cDados = new ClassDados();
foreach (CheckBox c in checkboxes)
{
if (c.IsChecked == true)
{
cDados.Pedido = c.Content.ToString();
lista.Add(cDados);
}
}
Frame.Navigate(typeof(Carrinho), (lista));
My Class:
class ClassDados
{
public string Pedido { get; set; }
public int Valor { get; set; }
}
Page 2
public sealed partial class Carrinho : Page
{
List<ClassDados> lista = new List<ClassDados>();
public Carrinho()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ClassDados c = e.Parameter as ClassDados;
Cardapio car = e.Parameter as Cardapio;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ClassDados c = e.Parameter as ClassDados;
Cardapio car = e.Parameter as Cardapio;
}
}
My point is: receive the data of page 1 and fill listview/richtexbox control with the data of page 1, but I can't do this, because my way to do this is the same on C# Windows Forms, but is different to windows phone, anyone can help me?
The problem is that you want to receive an object of type ClassDados
on Page 2, although on Page 1 you pass a List of ClassDados List<ClassDados> lista
. So on Page 2 write List<ClassDados> lista = e.Parameter as List<ClassDados>
. That should do the trick. Also, make sure you check for null when retrieving object from e.Parameter
!