How to populate picker from view model

DevMaranDevMaran Member ✭✭
edited August 2018 in Xamarin.Forms

How I can show the "LookupName" field of "ClassEntity" in the Picker options?.

I have a Model class:

public class ClassEntity
{
    public int LookupId { get; set; }
    public int LookupGroupId { get; set; }
    public string LookupCode { get; set; }
    public string LookupName { get; set; }
    public string LookupData { get; set; }
    public string CodeDesc { get; set; }
    public bool IsActive { get; set; }
    public bool IsSystem { get; set; }
    public int SortOrder { get; set; }
    public string CreatedBy { get; set; }
    public DateTime CreatedDate { get; set; }
    public string UpdatedBy { get; set; }
    public DateTime UpdatedDate { get; set; }
}

public class ClassLookUpModel
{
    public List<ClassEntity> Entity { get; set; }
    public int Status { get; set; }
    public object Exception { get; set; }
    public string Message { get; set; }
} 

In ViewModel Class:

public class StudentDetailsViewModel
{
ClassLookUpModel classes { get; set; }

    WebServiceClient apiClient = new WebServiceClient();

    public StudentDetailsViewModel()
    {
        intializePicker();
    }

    public async void intializePicker()
    { 
        await Application.Current.MainPage.Navigation.PushPopupAsync(new LoadingIndicator());
        classes = await apiClient.getClasses();
        if (classes.Message.ToString() == "Success")
        { 
            await Application.Current.MainPage.Navigation.PopPopupAsync(true);
        }

    }

}

** Code Behind file I have bound the ViewModel: **

public StudenceAttendancePage()
    {
        InitializeComponent();
        BindingContext = new StudentDetailsViewModel();
    }

** I have tried In Xaml:**

Best Answer

Answers

  • DevMaranDevMaran Member ✭✭
    edited August 2018

    @seanyda, Thanks for the quick answer.

Sign In or Register to comment.