In my viewmodelA, I have a property that when the button from my fragmentA.axml is clicked, I do Mvxbind and the screen changes and it shows viewmodelB and also I send an http request and I am getting response as expected. This works exactly how I want it to work. But the problem is, I can seem to show that response in my fragmentB.axml page (someNumber and status). Can anyone help me out with this problem. Thanks!!
ViewmodelA.cs:
public MvxCommand SomeCommand
{
get
{
return new MvxCommand(() => something());
}
}
public async void something()
{
ShowViewModel<ViewModelB>();
SomeService serviceWrapper = new SomeService();
var model = {//Some Json request};
var result = await serviceWrapper.SubmitRequestAsync(model);
SomeResponse response = StaticMethods.DeserializeJson<SomeResponse>(result);
Status = response.SomeResponse1.Activity[0].Status.Description;
SomeNumber = response.SomeResponse1.SomeNumber;
Debug.WriteLine("SomeNumber : " + SomeNumber );
Debug.WriteLine("Status: " + Status);
}
private string _someNumber;
public string SomeNumber
{
get
{
return _someNumber;
}
set
{
SetProperty(ref _someNumber, value);
RaisePropertyChanged(() => SomeNumber);
}
}
private string _status;
public string Status
{
get
{
return _status;
}
set
{
SetProperty(ref _status, value);
RaisePropertyChanged(() => Status);
}
}
fragmentA.axml
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/Submit"
local:MvxBind="Click SomeCommand" />
fragmentB.axml
<TextView
android:text="Some Number:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/SomeNum"
local:MvxBind="Text SomeNumber "/>
<TextView
android:text="Status:"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/status"
local:MvxBind="Text Status"/>
As far as I can see you got two options:
First option is to wait to send you http call until you are in ViewModelB, and load the data over there.
Second option is to wait until your http call has finished before navigating, and sending the data fetched in ViewModelA as a navigation parameter for ViewModelB.