コード例 #1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="ItemsSourceAdapter" /> class.
 /// </summary>
 public ItemsSourceAdapter([NotNull] object container, Context context, bool listenCollectionChanges, string dropDownItemTemplateSelectorName = null,
     string itemTemplateSelectorName = AttachedMemberConstants.ItemTemplateSelector, string dropDownItemTemplateIdName = null,
     string itemTemplateIdName = AttachedMemberConstants.ItemTemplate)
 {
     Should.NotBeNull(container, "container");
     _container = container;
     _itemTemplateProvider = new DataTemplateProvider(container, itemTemplateIdName, itemTemplateSelectorName);
     _dropDownTemplateProvider = new DataTemplateProvider(container,
         dropDownItemTemplateIdName ?? AttachedMembers.AdapterView.DropDownItemTemplate,
         dropDownItemTemplateSelectorName ?? AttachedMembers.AdapterView.DropDownItemTemplateSelector);
     _layoutInflater = context.GetBindableLayoutInflater();
     if (listenCollectionChanges)
         _weakHandler = ReflectionExtensions.MakeWeakCollectionChangedHandler(this, (adapter, o, arg3) => adapter.OnCollectionChanged(o, arg3));
     var activityView = context.GetActivity() as IActivityView;
     if (activityView != null)
     {
         _listener = ReflectionExtensions.CreateWeakEventHandler<ItemsSourceAdapter, EventArgs>(this, (adapter, o, arg3) => adapter.ActivityViewOnDestroyed((Activity)o));
         activityView.Mediator.Destroyed += _listener.Handle;
     }
 }
コード例 #2
0
 public ItemsSourceAdapter([NotNull] object container, Context context, bool listenCollectionChanges, string dropDownItemTemplateSelectorName = null,
     string itemTemplateSelectorName = null, string dropDownItemTemplateName = null, string itemTemplateName = null)
 {
     Should.NotBeNull(container, "container");
     _container = container;
     container.TryGetBindingMemberValue(AttachedMembers.Object.StableIdProvider, out _stableIdProvider);
     _itemTemplateProvider = new DataTemplateProvider(container, itemTemplateName ?? AttachedMemberConstants.ItemTemplate,
         itemTemplateSelectorName ?? AttachedMemberConstants.ItemTemplateSelector);
     _dropDownTemplateProvider = new DataTemplateProvider(container,
         dropDownItemTemplateName ?? AttachedMembers.AdapterView.DropDownItemTemplate,
         dropDownItemTemplateSelectorName ?? AttachedMembers.AdapterView.DropDownItemTemplateSelector);
     _layoutInflater = context.GetBindableLayoutInflater();
     if (listenCollectionChanges)
         _weakHandler = ReflectionExtensions.MakeWeakCollectionChangedHandler(this, (adapter, o, arg3) => adapter.OnCollectionChanged(o, arg3));
     var activityView = context.GetActivity() as IActivityView;
     if (activityView != null)
     {
         _listener = ReflectionExtensions.CreateWeakEventHandler<ItemsSourceAdapter, EventArgs>(this, (adapter, o, arg3) => adapter.ActivityViewOnDestroyed((Activity)o));
         activityView.Mediator.Destroyed += _listener.Handle;
     }
     _defaultDropDownTemplate = IsSpinner()
         ? global::Android.Resource.Layout.SimpleDropDownItem1Line
         : global::Android.Resource.Layout.SimpleSpinnerDropDownItem;
     var absListView = container as AdapterView;
     if (absListView != null)
     {
         var member = BindingServiceProvider.MemberProvider.GetBindingMember(absListView.GetType(), AttachedMembers.ViewGroup.DisableHierarchyListener, false, false);
         if (member.CanWrite)
             member.SetSingleValue(absListView, Empty.TrueObject);
     }
 }