2014-12-19 82 views
0

我正在爲Android/iOS應用程序使用MvvmCross 3.2.2,並且遇到不刷新的MvxListView和使用DrawableName綁定的ImageView,除非有關項目在屏幕上滾動並返回。MvvmCross Android MvxListView DrawableName不刷新

的DataModel

public class VehicleStatus 
{ 
    public string VehicleRegistration { get; set; } 
    public bool Selected { get; set; } 
    public string DrawableName 
    { 
     get 
     { 
      string res = (Selected) ? "on" : "off"; 
      return res; 
     } 
    } 
} 

兩個 「開」 和 「關」 是是可繪製文件夾內的PNG資源。

MvxListView佈局摘錄

 <Mvx.MvxListView 
      android:id="@+id/listItems" 
      android:layout_height="fill_parent" 
      android:layout_width="fill_parent" 
      android:dividerHeight="2dp" 
      android:divider="@drawable/list_divider" 
      local:MvxBind="ItemsSource Units; ItemClick VehicleSelectedCommand" 
      local:MvxItemTemplate="@layout/list_unit" /> 

MvxItemTemplate

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res/xxxxxxx.Droid" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:background="@color/white" 
    android:layout_height="62dp"> 
    <TextView 
     android:id="@+id/unitsName" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:textSize="18dp" 
     android:gravity="center" 
     android:layout_margin="7dp" 
     android:textColor="@color/verydarknavy" 
     local:MvxBind="Text VehicleRegistration" /> 
    <ImageView 
     android:id="@+id/notificationUnitImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="21dp" 
     android:layout_centerVertical="true" 
     android:layout_alignParentRight="true" 
     local:MvxBind="DrawableName DrawableName " 
     android:tint="@color/verydarknavy" /> 
</RelativeLayout> 

視圖模型

private ObservableCollection<VehicleStatus> _units; 
    public ObservableCollection<VehicleStatus> Units 
    { 
     get { return _units; } 
     set { _units = value; 
      RaisePropertyChanged (() => Units); } 
    } 

和命令

public void VehicleSelected (VehicleStatus item) 
    { 
     if (item != null) 
     { 
      foreach (var unit in _units) 
      { 
       if (unit.Id == item.Id) 
       { 
        unit.Selected = !unit.Selected; 
        break; 
       } 
      } 
      RaisePropertyChanged (() => Units); 
     } 
    } 

    private MvxCommand<VehicleStatus> _vehicleSelectedCommand; 
    public System.Windows.Input.ICommand VehicleSelectedCommand 
    { 
     get 
     { 
      _vehicleSelectedCommand = _vehicleSelectedCommand ?? new MvxCommand<VehicleStatus>(VehicleSelected); 
      return _vehicleSelectedCommand; 
     } 
    } 

我認爲這是源的所有相關位。我認爲我錯過了一些讓ImageView刷新的東西,但我不知道是什麼。任何想法,將不勝感激。

回答

2

嘗試:

  • 繼承VehicleStatusMvxNotifyPropertyChanged
  • VehicleStatus信號中使用RaisePropertyChanged()調用的變化發生

對於獎勵積分的變化,這也可能是很好的使用轉換器將Selected屬性自動更改爲DrawableName

+0

謝謝斯圖爾特,現在像一個夢一樣運作!!!! – JDibble