我有使用MvxExpandableListView
public class ExpandView : MvxActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.ExpandView);
MvxExpandableListView list = FindViewById<MvxExpandableListView>(Resource.Id.TheExpandView);
list.SetAdapter(new MyCustomAdaptor(this, (IMvxAndroidBindingContext)BindingContext));
}
private class MyCustomAdaptor : MvxExpandableListAdapter
{
private IList _itemsSource;
public MyCustomAdaptor(Context context, IMvxAndroidBindingContext bindingContext)
: base(context, bindingContext)
{
}
protected override void SetItemsSource(IEnumerable value)
{
Mvx.Trace("Setting itemssource");
if (_itemsSource == value)
return;
var existingObservable = _itemsSource as INotifyCollectionChanged;
if (existingObservable != null)
existingObservable.CollectionChanged -= OnItemsSourceCollectionChanged;
_itemsSource = value as IList;
var newObservable = _itemsSource as INotifyCollectionChanged;
if (newObservable != null)
newObservable.CollectionChanged += OnItemsSourceCollectionChanged;
if (value != null)
{
}
else
base.SetItemsSource(null);
}
}
}
加载视图时,不会调用覆盖方法 SetItemsSource ,但是当我尝试离开页面 SetItemsSource 时,会调用null值。
答案 0 :(得分:0)
您需要设置属性ItemsSource
。查看MvxAdapter
的来源:
[MvxSetToNullAfterBinding]
public virtual IEnumerable ItemsSource
{
get { return _itemsSource; }
set { SetItemsSource(value); }
}
ItemsSource
的设置者调用方法SetItemsSource
。
MvxExpandableListAdapter
继承MvxAdapter
。
<强>来源:强> http://repo.typesafe.com/typesafe/releases/ https://github.com/MvvmCross/MvvmCross/blob/4.0/MvvmCross/Binding/Droid/Views/MvxExpandableListAdapter.cs