2014-12-19 46 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