2016-09-21 67 views
0

我有這樣的代碼片段使用MvxExpandableListViewMvxExpandableListAdapter SetItemsSource不叫

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被調用一個空值。

回答

0

您需要設置該屬性ItemsSource .Looking在MvxAdapter來源:

[MvxSetToNullAfterBinding] 
public virtual IEnumerable ItemsSource 
{ 
    get { return _itemsSource; } 
    set { SetItemsSource(value); } 
} 

ItemsSource setter方法調用該方法SetItemsSource

MvxExpandableListAdapter繼承MvxAdapter

來源: https://github.com/MvvmCross/MvvmCross/blob/4.0/MvvmCross/Binding/Droid/Views/MvxExpandableListAdapter.cs https://github.com/MvvmCross/MvvmCross/blob/4.0/MvvmCross/Binding/Droid/Views/MvxAdapter.cs

+0

我已經設定在XML中的ItemSource地方:MvxBind = 「XYZ的ItemsSource」 –