I have a page where I bind a command to a button. When I click it I calls a method where I get the data I want from an API.What if I don't want to only bind the data at the view but also use these data in code behind?! Lets say this is my view :
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="HelloWorld.Pages.JohnDoePage" xmlns:local="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Pages" xmlns:vm="clr-namespace:HelloWorld.ViewModel;assembly=HelloWorld"> <StackLayout Padding="20, 10" HorizontalOptions="Center"> <Button Command="{Binding JohnDoe}" Text="Data about John Doe" /> </StackLayout> </ContentPage> the code behihnd :
Models.Info info; public JohnDoePage(Models.Info info) { InitializeComponent(); BindingContext = new InfoDetailsViewModel(info); this.info= info; // i want to use the data here //using the data } the view model :
Data _data; public Data Data { get { return _data; } set { if (value == _data) return; _data = value; OnPropertyChanged(); } } public ICommand JohnDoe { get { return new Command(async () => { var Dataa = await _apiServices.InfoAboutJohnDOe(); }); } } and the service where I get the data I need is OK. I'm using the same viewmodel for binding different commands, and I don't know if this is possible by the way so I'm stuck. Any idea how can I use the data I get in the view code-behind?? Thanks in advance!!