Hi
I'm trying to get a picker working for a custom class. My ItemsSource binding works fine but when I select an item the breakpoint I have in the property setter is not hit.
I looked at the MonkeyApp sample and copied some code from that (I can't run the sample directly as it needs Windows 10 and I'm on W7 using VS Community 2017) but I'm having the same problem with the sample code.
I implemented another picker to select from a list of strings where SelectedItem is bound to a public string property, for this picker the property setter breakpoint is hit.
I read something that suggested older versions of the Picker/Xamarin forms might not work so I used Nuget to install Xamarin.Forms 3.1.0.583944. Still doesn't work.
xaml:
<Picker Title="string list" ItemsSource="{Binding StringList}" SelectedItem="{Binding SelectedString}"/>
<Label Text="{Binding SelectedString}"/>
<Picker Title="Select a monkey" ItemsSource="{Binding Monkeys}" ItemDisplayBinding="{Binding Name}"
SelectedItem="{Binding SelectedMonkey, Mode=TwoWay}" />
<Label Text="{Binding SelectedMonkey.Location}" FontAttributes="Italic" HorizontalOptions="Center" />
viewmodel:
string selectedString;
public string SelectedString
{
get
{
return selectedString;
}
set
{
selectedString = value;
OnPropertyChanged();
}
}
Monkey selectedMonkey;
public Monkey SelectedMonkey
{
get { return selectedMonkey; }
set
{
if (selectedMonkey != value)
{
selectedMonkey = value;
OnPropertyChanged();
}
}
}
ViewModelBase class:
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Can anyone tell me where I am going wrong?
Thanks in advance.