1
我使用Xamarin(Android)+ Mvvmcross創建了簡單的應用程序。我有我的ViewModel屬性數據(鍵入MyData)。MVVMCross Android:綁定值未更新
這是我VievModel
public class MyViewModel:MvxViewModel
{
private MyData _data;
public MyData Data
{
get { return _data; }
set
{
_data = value;
RaisePropertyChanged(() => Data);
}
}
....
}
public class MyData: INotifyPropertyChanged
{
public string Current
{
get { return _current; }
set
{
_current = value;
Debug.WriteLine(_current);
NotifyPropertyChanged("Current");
}
}
private string _current;
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
我用鑑於
xmlns:local="http://schemas.android.com/apk/res-auto"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="Text Data.Current"
android:id="@+id/textView" />
這種結合這是我的計時器:
private Timer _timer;
.....
public void InitEvent(Action action)
{
_timer.Elapsed += TimerTick;
_action = action;
}
private void TimerTick(object sender, ElapsedEventArgs e)
{
if (_action != null)
_action();
}
在_action更新proprrty電流。
更新value屬性時TextView中的文本不會更改。問題是什麼? 該值在計時器上發生變化。 Debug.WriteLine(_current) - 顯示新的值。 TextView.Text - 舊值,未更新。
我沒有改變我的回答 – Stuart
它的作品。謝謝。 – FetFrumos