简体   繁体   中英

OnChangeListener on Picker in Xamarin.Forms

Am having two pickers and i got each SelectedItem from the Pickers but they are not Firing my Method whenever i change there Values Why ?

Below is my Code :

This how i declared the selected Indices of Each Picker:

int selectedIndexYear = year_pk.SelectedIndex;
int selectedIndexTerm = term_pk.SelectedIndex;

Here is the logic behind of firing whenever i change the picker , but it's not working :

if (selectedIndexYear != -1 && selectedIndexTerm != -1)
{
    int term = Int32.Parse(term_pk.SelectedItem.ToString());
    //Below  is my method am Firing Each change of the Picker.
    OnResultsList(year_pk.SelectedItem.ToString(), term);
}

According to that scenario , i see you want to fire an Event whenever there's a change of an Item selected on a picker.

I recommend you to use SelectedIndexChanged Event as below :

year_pk.SelectedIndexChanged += delegate 
{
    int term = Int32.Parse(term_pk.SelectedItem.ToString());
    //Below  is my method am Firing Each change of the Picker.
    OnResultsList(year_pk.SelectedItem.ToString(), term);
}

term_pk.SelectedIndexChanged += delegate 
{
    int term = Int32.Parse(term_pk.SelectedItem.ToString());
    //Below  is my method am Firing Each change of the Picker.
    OnResultsList(year_pk.SelectedItem.ToString(), term);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM