I am making simple mvvm binding with picker
field in xamarin.forms. I am following this guide xamarin guide setting a picker's bindings
So I made a model:
public class Operation
{
public int Number { get; set; }
public string Name { get; set; }
}
An ViewModel:
private List<Operation> _operations;
public List<Operation> Operations
{
get { return _operations; }
set
{
_operations = value;
OnPropertyChanged();
}
}
and View:
<Picker
ItemsSource="{Binding Operations}"
ItemDisplayBinding="{Binding Number}"
SelectedItem = "{Binding SelectedOperation}"/>
<Entry x:Name="HelpEntry"
Text="{Binding SelectedOperation.Name}" />
In the Pickers list items are displayed correctly, but when I Select an item number, then binding inside a Entry is not displayed.
Ouestion is, what am I doing wrong?
By the way.. I am doing this because I need to get an selected Operation's Name
as variable in my code-behind section, by using HelpEntry.Text. It's not a smartest way and do u have better idea to do that?
Any help would be much appreciate.
ObservableCollection
instead ofList
. Does the setter of theSelectedOperation
call theOnPropertyChange
method? – Alex