【发布时间】:2017-06-20 17:48:52
【问题描述】:
在我的 viewmodelA 中,我有一个属性,当单击我的 fragmentA.axml 中的按钮时,我执行 Mvxbind 并且屏幕发生变化,它显示 viewmodelB 并且我发送了一个 http 请求,并且我得到了预期的响应。这正是我希望它工作的方式。但问题是,我似乎可以在我的 fragmentB.axml 页面(someNumber 和状态)中显示该响应。谁能帮我解决这个问题。谢谢!!
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 我明白你在说什么,但是当我点击按钮时,我想发送 http 请求。但我的问题是我不知道如何在另一个视图模型的片段(即片段B)中显示该数据。如果你知道我该如何解决这个问题,请告诉我。谢谢
标签: c# android xamarin mvvmcross mvxbind