在我viewmodelA,我有一個屬性,當我的fragmentA.axml按鈕被點擊,我做Mvxbind和屏幕更改,它顯示viewmodelB,我也發送一個http請求,我是得到預期的迴應。這正是我希望它工作的方式。但問題是,我似乎可以在我的fragmentB.axml頁面中顯示該響應(someNumber和status)。任何人都可以幫助我解決這個問題。謝謝!!MvvmCross - MvxBind沒有正確綁定
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"/>
您的類是否定義了:INotifyPropertyChanged?你沒有提供課堂定義 –
我有點困惑。看起來你正在嘗試導航到ViewModelB,但是你想在視圖中顯示的屬性是在ViewModelA中? – Ulbo
@Ulbo我看到你在說什麼,但我想發送http請求,當我點擊按鈕。但我的問題是,我不知道如何在另一個viewmodel的片段(即fragmentB)中顯示該數據。如果您知道我該如何處理這個問題,請告訴我。謝謝 –