Reputation: 1568
I have a picker inside an ObservableCollection, I need to bind the SelectedIndexChanged property with a custom command, since it will do some changes to the very same instance of object that contains this Picker and no outside this. I know the BindingContext is properly set, because the ItemsSource are loading as expected. But VS don't compiles and show this message:
Binding SelectedIndexChanged: No property, BindableProperty, or event found for "SelectedIndexChanged", or mismatching type between value and property.
This is how my code looks:
public event EventHandler HourChangedIndex
{
add
{
HourChangedIndex += new EventHandler((sender, e) =>
{
Hours.Add(((Picker)sender).SelectedItem as string);
Hours = new ObservableCollection<string>(Hours.OrderBy(i => i));
});
}
remove
{
HourChangedIndex -= new EventHandler((sender, e) =>
{
Hours.Add(((Picker)sender).SelectedItem as string);
Hours = new ObservableCollection<string>(Hours.OrderBy(i => i));
});
}
}
What I'm doing wrong or missing here?
Upvotes: 0
Views: 406
Reputation: 4302
You can check this doc.
It describes the relationship between SelectedIndexChanged
and SelectedIndex
in detail.
A Picker supports selection of one item at a time. When a user selects an item, the SelectedIndexChanged event fires, the SelectedIndex property is updated to an integer representing the index of the selected item in the list, and the SelectedItem property is updated to the object representing the selected item. The SelectedIndex property is a zero-based number indicating the item the user selected. If no item is selected, which is the case when the Picker is first created and initialized, SelectedIndex will be -1.
Upvotes: 1