We are using Xamarin.Forms for our project and subscribed a MessagingCenter call onto the DisplayAlert
and DisplayActionSheet
native functions.
Here's how we subscribed it in our view:
MessagingCenter.Subscribe<ViewModelBase, List<string>> (this, "DisplayActionSheet", (sender, values) => {
string title = values[0];
values.RemoveAt(0);
DisplayActionSheet (title, "Annuler", null, values.ToArray());
});
Here's how we implemented it in our ViewModel
:
public async void DisplayActionSheet(string title, string[] actions){
List<string> values = new List<string>(actions);
values.Insert (0, title);
MessagingCenter.Send<ViewModelBase, List<string>> (this, "DisplayActionSheet", values);
}
So we can call it this way:
string[] actions = {"Charmander", "Pikachu", "Squirtle"};
DisplayActionSheet("Choose your pokemon", actions);
How can we return a value to the message sender?