Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have build a xamarin project which populates a list of items in a listview on the homepage. I need to pass a variable on this page to the ViewModel class. How do i do that??? Help will be appreciated.

My Home page code is as below:

private async void LstItems_OnItemTapped(object o, ItemTappedEventArgs e )

    {
        var ItemCodeParam = e.Item as Item;

         var ItemCode = ItemCodeParam.ItemCode;

         await Navigation.PushAsync(new DetailItemPage(ItemCode));
I need to pass the ItemCode to my ViewModel Class.

    }


My View Model is as below

namespace MyFirstDbApp.ViewModels { public class ItemDetailsViewModel : INotifyPropertyChanged { private List _itemsList;

    public List<Item> ItemsList



    {
        get { return _itemsList; }

        set
        {
            _itemsList = value;
            OnPropertyChanged();
        }
    }

    public ItemDetailsViewModel()
    {

        InitializeDataAsync();
    }


    private async Task InitializeDataAsync()
    {






        var result = await ItemServices.GetItemsAsync().ConfigureAwait(false);

        ItemsList = result.Where(x => x.ItemCode == "").ToList();


    }


    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
}


I need to pass the ItemCode in the Homepage to the ViewModel "
Where(x => x.ItemCode == "")
"

How can i do this??? Help will be appreciated

What I have tried:

<pre>I have build a xamarin project which populates a list of items in a listview on the homepage. I need to pass a variable on this page to the ViewModel class. How do i do that??? Help will be appreciated.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900