Im trying to pass parameter to viewmodel in Xamarin.Forms.But Also I want to use it while loading the page ,to call a rest service with that parameter.But In load event parameter is null always.(I can see that parameter if I bind it to a label or etc...) How can I make it work properly and use that parameter inside the load event of viewmodel? Any help is appreciated,thanks
here is the button click event and navigate to Samplepage.
private void OntaptedBildirimItem(string param)
{
this._navigationService.NavigateTo(nameof(Views.SamplePage), param);
}
this is the Sample Page Viewmodel
private string _id;
public string id
{
get
{
return _id;
}
set
{
Set(() => id, ref _id, value);
}
}
public SamplePageViewModel(INavigationService navigationService) : base(navigationService)
{
this._navigationService = navigationService;
this.Title = "Sample Page=" + id; // here the id is always null,but if I use it to bind a label in xaml ,it has a value.
}
This is the SamplePage Code
public SamplePage(string parameter)
{
InitializeComponent();
var viewModel = this.BindingContext as ViewModels.SamplePageViewModel;
if(viewModel != null && parameter != null)
{
viewModel.bildirimid = parameter;
}
}