Member 12956755 Ответов: 0

Как получить доступ к переменной на моей домашней странице в моем классе viewmodel?


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));
    }
}
}


Мне нужно передать ItemCode на главной странице в ViewModel "
Where(x => x.ItemCode == "")
"

Как я могу это сделать??? Помощь будет оценена по достоинству

Что я уже пробовал:

<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.

0 Ответов