Passing data from list to new view xamarin

Ive created a picker with data inside, when selected the data is added to a list. I want to the values that are added to the list to follow to the next page when calculate button is pressed.. tried a few different approaches but i cant get it right..

.cs

// add from picker to listview function

    ObservableCollection<LayersClass> listProducts = new ObservableCollection<LayersClass>();

    private void MainPicker_SelectedIndexChanged(object sender, EventArgs e)
    {
        // feedback popup box
         var product = MainPicker.Items[MainPicker.SelectedIndex];
         DisplayAlert(product, "Layer added to calculation list", "OK");
        // if selected add to list          
        if (null != product)
        {
            LayersClass layer = new LayersClass();
            layer.Product = product;
            listProducts.Add(layer);
        }        
    }

    //calculate button
    private async void Button_Clicked(object sender, EventArgs e)
    {

        // send selected values to CalculationPage ??
        await Navigation.PushAsync(new CalculationPage());
    }

Xaml Code:

<ListView  
              x:Name="productsListView"
              HasUnevenRows="False" 
              HorizontalOptions="FillAndExpand"
              VerticalOptions="FillAndExpand" 
              BackgroundColor="White">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.ContextActions>
                        <MenuItem Clicked="MenuItem_Clicked" Text="Delete" IsDestructive="true" CommandParameter="{Binding .}" />
                    </ViewCell.ContextActions>
                    <StackLayout>
                        <Label Text="{Binding Product}"></Label>
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    <Button Margin="0,0,0,90" Text="Calculate" Clicked="Button_Clicked"  FontSize="Medium" TextColor="#00AB8E"  HorizontalOptions="Center"      BackgroundColor="Transparent"/>

Best Answer

Answers

Sign In or Register to comment.