Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Passing object array to another page through constructor

$
0
0

Hi, so basically, I've been having some trouble accessing an array of objects that I passed to the target page through the constructor. The array is an array of drink objects, each having a name, price and description, I created the drink class myself. I have a grid of drink items on which the user can click and select which drinks they wish to purchase, these are then saved in an array, however I cannot access the information from the objects on the following content page, which is essentially an invoice page. I've searched extensively and haven't found anything else closely related to my problem on these forums, I'd greatly appreciate some input.

The array is as so, every time the user taps a drink they would like to select, the array size is increased and the selected drink item is added to the new empty position in the array.

public static int selectedDrinks = 0;
public static Drink[] SelectedDrinks = new Drink[selectedDrinks];

The constructor for each drink item is as below:

public Drink Carling = new Drink ("Carling", 2.50, "1pt Beer");

The command that calls the instance of the 'invoice' class is like this:

Command navigateCommand = 
                new Command (async () =>
                    {
                        await Navigation.PushModalAsync(new PaymentPage (SelectedDrinks));
                    });

And the array is implemented in the following class like this:

`public class PaymentPage : ContentPage
{
public static Drink[] SelectedDrinks = null;

    public PaymentPage (Drink[] Drinks)
    {
        SelectedDrinks = Drinks;
    }
}

`

Thank you


Viewing all articles
Browse latest Browse all 58056

Trending Articles