protected override IBindingPathMembers UpdateInternal(IBindingPathMembers oldPath, bool hasSubscribers)
        {
            object source = GetActualSource();

            if (source == null || source.IsUnsetValue())
            {
                return(UnsetBindingPathMembers.Instance);
            }
            bool allMembersAvailable = true;
            IBindingMemberProvider memberProvider = BindingServiceProvider.MemberProvider;
            IList <string>         items          = Path.Parts;

            //Trying to get member using full path with dot, example BindingErrorProvider.Errors or ErrorProvider.Errors.
            if (items.Count == 2)
            {
                var pathMember = memberProvider.GetBindingMember(source.GetType(), Path.Path, _ignoreAttachedMembers, false);
                if (pathMember != null)
                {
                    var observer = TryObserveMember(source, pathMember, true);
                    if (observer != null)
                    {
                        _listeners.Add(observer);
                    }
                    return(new MultiBindingPathMembers(_lastMemberListener.Reference, source, new[] { pathMember }));
                }
            }


            int lastIndex = items.Count - 1;
            var members   = new List <IBindingMemberInfo>();

            for (int index = 0; index < items.Count; index++)
            {
                string             name       = items[index];
                IBindingMemberInfo pathMember = memberProvider
                                                .GetBindingMember(source.GetType(), name, _ignoreAttachedMembers, true);
                members.Add(pathMember);
                var observer = TryObserveMember(source, pathMember, index == lastIndex);
                if (observer != null)
                {
                    _listeners.Add(observer);
                }
                if (index == lastIndex)
                {
                    break;
                }
                source = pathMember.GetValue(source, null);
                if (source == null || source.IsUnsetValue())
                {
                    allMembersAvailable = false;
                    break;
                }
            }

            return(allMembersAvailable
                ? new MultiBindingPathMembers(_lastMemberListener.Reference, source, members)
                : UnsetBindingPathMembers.Instance);
        }
        private static void Register(IBindingMemberProvider memberProvider)
        {
            BindingBuilderExtensions.RegisterDefaultBindingMember <Entry>(() => t => t.Text);
            BindingBuilderExtensions.RegisterDefaultBindingMember <Label>(() => t => t.Text);
            BindingBuilderExtensions.RegisterDefaultBindingMember <Button>("Clicked");
            BindingBuilderExtensions.RegisterDefaultBindingMember <ToolbarItem>("Clicked");
            BindingBuilderExtensions.RegisterDefaultBindingMember <ListView>(() => c => c.ItemsSource);
            BindingBuilderExtensions.RegisterDefaultBindingMember <ProgressBar>(() => c => c.Progress);

            //Element
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Element, object>(AttachedMemberConstants.Parent, GetParentValue, SetParentValue, ObserveParentMember));
            memberProvider.Register(typeof(Element), "BindingContext", BindingMemberProvider.BindingContextMember, true);

            //VisualElement
            var visibleMember = memberProvider.GetBindingMember(typeof(VisualElement),
                                                                ToolkitExtensions.GetMemberName <VisualElement>(() => element => element.IsVisible), true, false);

            if (visibleMember != null)
            {
                memberProvider.Register(typeof(VisualElement), "Visible", visibleMember, true);
                memberProvider.Register(AttachedBindingMember.CreateMember <VisualElement, bool>("Hidden",
                                                                                                 (info, element) => !element.IsVisible, (info, element, arg3) => element.IsVisible = !arg3,
                                                                                                 (info, element, arg3) => visibleMember.TryObserve(element, arg3)));
            }
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <VisualElement, object>(AttachedMemberConstants.FindByNameMethod, FindByNameMemberImpl));

            memberProvider.Register(AttachedBindingMember.CreateMember <VisualElement, bool>(AttachedMemberConstants.Focused, (info, element) => element.IsFocused,
                                                                                             (info, element, arg3) =>
            {
                if (arg3)
                {
                    element.Focus();
                }
                else
                {
                    element.Unfocus();
                }
            }, (info, element, arg3) => BindingServiceProvider.WeakEventManager.Subscribe(element, "IsFocused", arg3)));

            var enabledMember = memberProvider.GetBindingMember(typeof(VisualElement),
                                                                ToolkitExtensions.GetMemberName <VisualElement>(() => element => element.IsEnabled), true, false);

            if (enabledMember != null)
            {
                memberProvider.Register(typeof(VisualElement), AttachedMemberConstants.Enabled, enabledMember, true);
            }

            //Toolbar item
            enabledMember = memberProvider.GetBindingMember(typeof(ToolbarItem), "IsEnabled", true, false);
            if (enabledMember != null)
            {
                memberProvider.Register(typeof(ToolbarItem), AttachedMemberConstants.Enabled, enabledMember, true);
            }
        }
        private static void Register(IBindingMemberProvider memberProvider)
        {
            //Element
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Element, object>(AttachedMemberConstants.Parent, GetParentValue, null, ObserveParentMember));
            memberProvider.Register(typeof(Element), "BindingContext", BindingMemberProvider.BindingContextMember, true);

            //VisualElement
            var visibleMember = memberProvider.GetBindingMember(typeof(VisualElement),
                                                                ToolkitExtensions.GetMemberName <VisualElement>(element => element.IsVisible), true, false);

            if (visibleMember != null)
            {
                memberProvider.Register(typeof(VisualElement), "Visible", visibleMember, true);
                memberProvider.Register(AttachedBindingMember.CreateMember <VisualElement, bool>("Hidden",
                                                                                                 (info, element) => !element.IsVisible, (info, element, arg3) => element.IsVisible = !arg3,
                                                                                                 (info, element, arg3) => visibleMember.TryObserve(element, arg3)));
            }
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <VisualElement, object>(AttachedMemberConstants.FindByNameMethod, FindByNameMemberImpl));

            memberProvider.Register(AttachedBindingMember.CreateMember <VisualElement, bool>(AttachedMemberConstants.Focused, (info, element) => element.IsFocused,
                                                                                             (info, element, arg3) =>
            {
                if (arg3)
                {
                    element.Focus();
                }
                else
                {
                    element.Unfocus();
                }
            }, (info, element, arg3) => BindingServiceProvider.WeakEventManager.Subscribe(element, "IsFocused", arg3)));

            var enabledMember = memberProvider.GetBindingMember(typeof(VisualElement),
                                                                ToolkitExtensions.GetMemberName <VisualElement>(element => element.IsEnabled), true, false);

            if (enabledMember != null)
            {
                memberProvider.Register(typeof(VisualElement), AttachedMemberConstants.Enabled, enabledMember, true);
            }

            //Toolbar item
            enabledMember = memberProvider.GetBindingMember(typeof(ToolbarItem), "IsEnabled", true, false);
            if (enabledMember != null)
            {
                memberProvider.Register(typeof(ToolbarItem), AttachedMemberConstants.Enabled, enabledMember, true);
            }
        }
        private static void RegisterDialogMembers(IBindingMemberProvider memberProvider)
        {
            memberProvider.Register(AttachedBindingMember.CreateMember <Element, object>(AttachedMemberConstants.Parent,
                                                                                         (info, element) => element.Parent ?? BindingExtensions.AttachedParentMember.GetValue(element, null),
                                                                                         (info, element, arg3) => BindingExtensions.AttachedParentMember.SetValue(element, arg3),
                                                                                         (info, element, arg3) => BindingExtensions.AttachedParentMember.TryObserve(element, arg3)));

            IBindingMemberInfo member = memberProvider.GetBindingMember(typeof(EntryElement), "Changed", true, false);

            if (member != null)
            {
                memberProvider.Register(AttachedBindingMember.CreateEvent <EntryElement>("ValueChanged",
                                                                                         (info, element, arg3) => member.TryObserve(element, arg3)));
            }

            memberProvider.Register(AttachedBindingMember.CreateEvent <StringElement>("Tapped",
                                                                                      (info, element, arg3) =>
            {
                var weakWrapper          = arg3.ToWeakWrapper();
                IDisposable unsubscriber = null;
                NSAction action          = () =>
                {
                    if (!weakWrapper.EventListener.TryHandle(weakWrapper.EventListener, EventArgs.Empty))
                    {
                        unsubscriber.Dispose();
                    }
                };
                unsubscriber = WeakActionToken.Create(element, action,
                                                      (stringElement, nsAction) => stringElement.Tapped -= nsAction);
                element.Tapped += action;
                return(unsubscriber);
            }));
        }
 public static TValue TryGetValue <TValue>([NotNull] this IBindingMemberProvider memberProvider, object item,
                                           [NotNull] string memberName, bool ignoreAttachedMembers = false, TValue defaultValue = default(TValue))
 {
     Should.NotBeNull(memberProvider, "memberProvider");
     return(memberProvider
            .GetBindingMember(item.GetType(), memberName, ignoreAttachedMembers, false)
            .TryGetValue(item, defaultValue));
 }
        public static IBindingMemberInfo TryFindMemberChangeEvent([NotNull] IBindingMemberProvider memberProvider,
                                                                  [NotNull] Type type, [NotNull] string memberName)
        {
            Should.NotBeNull(memberProvider, "memberProvider");
            var member = memberProvider.GetBindingMember(type, memberName + "Changed", false, false);

            if (member == null || member.MemberType != BindingMemberType.Event)
            {
                member = memberProvider.GetBindingMember(type, memberName + "Change", false, false);
            }

            if (member == null || member.MemberType != BindingMemberType.Event)
            {
                return(null);
            }
            return(member);
        }
        private static void Register(IBindingMemberProvider memberProvider)
        {
            BindingBuilderExtensions.RegisterDefaultBindingMember<Entry>(() => t => t.Text);
            BindingBuilderExtensions.RegisterDefaultBindingMember<Label>(() => t => t.Text);
            BindingBuilderExtensions.RegisterDefaultBindingMember<Button>("Clicked");
            BindingBuilderExtensions.RegisterDefaultBindingMember<ToolbarItem>("Clicked");
            BindingBuilderExtensions.RegisterDefaultBindingMember<ListView>(() => c => c.ItemsSource);
            BindingBuilderExtensions.RegisterDefaultBindingMember<ProgressBar>(() => c => c.Progress);

            //Element
            memberProvider.Register(AttachedBindingMember
                .CreateMember<Element, object>(AttachedMemberConstants.ParentExplicit, GetParentValue, SetParentValue, ObserveParentMember));
            memberProvider.Register(typeof(Element), "BindingContext", BindingMemberProvider.BindingContextMember, true);

            //VisualElement
            var visibleMember = memberProvider.GetBindingMember(typeof(VisualElement),
                ToolkitExtensions.GetMemberName<VisualElement>(() => element => element.IsVisible), true, false);
            if (visibleMember != null)
            {
                memberProvider.Register(typeof(VisualElement), "Visible", visibleMember, true);
                memberProvider.Register(AttachedBindingMember.CreateMember<VisualElement, bool>("Hidden",
                    (info, element) => !element.IsVisible, (info, element, arg3) => element.IsVisible = !arg3,
                    (info, element, arg3) => visibleMember.TryObserve(element, arg3)));
            }
            memberProvider.Register(AttachedBindingMember
                .CreateMember<VisualElement, object>(AttachedMemberConstants.FindByNameMethod, FindByNameMemberImpl));

            memberProvider.Register(AttachedBindingMember.CreateMember<VisualElement, bool>(AttachedMemberConstants.Focused, (info, element) => element.IsFocused,
                (info, element, arg3) =>
                {
                    if (arg3)
                        element.Focus();
                    else
                        element.Unfocus();
                }, (info, element, arg3) => BindingServiceProvider.WeakEventManager.Subscribe(element, "IsFocused", arg3)));

            var enabledMember = memberProvider.GetBindingMember(typeof(VisualElement),
                ToolkitExtensions.GetMemberName<VisualElement>(() => element => element.IsEnabled), true, false);
            if (enabledMember != null)
                memberProvider.Register(typeof(VisualElement), AttachedMemberConstants.Enabled, enabledMember, true);

            //Toolbar item
            enabledMember = memberProvider.GetBindingMember(typeof(ToolbarItem), "IsEnabled", true, false);
            if (enabledMember != null)
                memberProvider.Register(typeof(ToolbarItem), AttachedMemberConstants.Enabled, enabledMember, true);
        }
        /// <summary>
        ///     Updates the current values.
        /// </summary>
        protected override void UpdateInternal()
        {
            try
            {
                ClearListeners();
                object source = GetActualSource();
                if (source == null || source.IsUnsetValue())
                {
                    _members = UnsetBindingPathMembers.Instance;
                    return;
                }
                bool allMembersAvailable = true;
                IBindingMemberProvider memberProvider = BindingServiceProvider.MemberProvider;
                IList <string>         items          = Path.Parts;
                int lastIndex = items.Count - 1;
                var members   = new List <IBindingMemberInfo>();
                for (int index = 0; index < items.Count; index++)
                {
                    string             name       = items[index];
                    IBindingMemberInfo pathMember = memberProvider
                                                    .GetBindingMember(source.GetType(), name, _ignoreAttachedMembers, true);
                    members.Add(pathMember);
                    var observer = TryObserveMember(source, pathMember, index == lastIndex);
                    if (observer != null)
                    {
                        _listeners.Add(observer);
                    }
                    if (index == lastIndex)
                    {
                        break;
                    }
                    source = pathMember.GetValue(source, null);
                    if (source == null || source.IsUnsetValue())
                    {
                        allMembersAvailable = false;
                        break;
                    }
                }

                _members = allMembersAvailable
                    ? new MultiBindingPathMembers(_selfReference, source, Path, members)
                    : UnsetBindingPathMembers.Instance;
            }
            catch (Exception)
            {
                _members = UnsetBindingPathMembers.Instance;
                throw;
            }
        }
        private static void RegisterDialogMembers(IBindingMemberProvider memberProvider)
        {
            BindingBuilderExtensions.RegisterDefaultBindingMember <Element>(nameof(Element.Caption));
            memberProvider.Register(AttachedBindingMember.CreateMember <Element, string>(nameof(Element.Caption),
                                                                                         (info, element) => element.Caption,
                                                                                         (info, element, arg3) =>
            {
                element.Caption = arg3;
                element.Reload();
            }));
            memberProvider.Register(AttachedBindingMember.CreateMember <Element, object>(AttachedMemberConstants.ParentExplicit,
                                                                                         (info, element) => element.Parent, null));

            BindingBuilderExtensions.RegisterDefaultBindingMember <EntryElement>(nameof(EntryElement.Value));
            IBindingMemberInfo member = memberProvider.GetBindingMember(typeof(EntryElement), nameof(EntryElement.Changed), true, false);

            if (member != null)
            {
                memberProvider.Register(AttachedBindingMember.CreateEvent <EntryElement>("ValueChanged",
                                                                                         (info, element, arg3) => member.TryObserve(element, arg3)));
            }

            BindingBuilderExtensions.RegisterDefaultBindingMember <StringElement>(nameof(StringElement.Value));
            memberProvider.Register(AttachedBindingMember.CreateMember <StringElement, string>(nameof(StringElement.Value),
                                                                                               (info, element) => element.Value,
                                                                                               (info, element, arg3) =>
            {
                element.Value = arg3;
                element.Reload();
            }));
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.StringElement.TappedEvent,
                                                                      (info, element, arg3) =>
            {
                var weakWrapper          = arg3.ToWeakWrapper();
                IDisposable unsubscriber = null;
                Action action            = () =>
                {
                    if (!weakWrapper.EventListener.TryHandle(weakWrapper.EventListener, EventArgs.Empty))
                    {
                        unsubscriber.Dispose();
                    }
                };
                unsubscriber = WeakActionToken.Create(element, action,
                                                      (stringElement, nsAction) => stringElement.Tapped -= nsAction);
                element.Tapped += action;
                return(unsubscriber);
            }));
        }
        private static void RegisterDialogMembers(IBindingMemberProvider memberProvider)
        {
            BindingBuilderExtensions.RegisterDefaultBindingMember<Element>(nameof(Element.Caption));
            memberProvider.Register(AttachedBindingMember.CreateMember<Element, string>(nameof(Element.Caption),
                (info, element) => element.Caption,
                (info, element, arg3) =>
                {
                    element.Caption = arg3;
                    element.Reload();
                }));
            memberProvider.Register(AttachedBindingMember.CreateMember<Element, object>(AttachedMemberConstants.ParentExplicit,
                (info, element) => element.Parent, null));

            BindingBuilderExtensions.RegisterDefaultBindingMember<EntryElement>(nameof(EntryElement.Value));
            IBindingMemberInfo member = memberProvider.GetBindingMember(typeof(EntryElement), nameof(EntryElement.Changed), true, false);
            if (member != null)
                memberProvider.Register(AttachedBindingMember.CreateEvent<EntryElement>("ValueChanged",
                    (info, element, arg3) => member.TryObserve(element, arg3)));

            BindingBuilderExtensions.RegisterDefaultBindingMember<StringElement>(nameof(StringElement.Value));
            memberProvider.Register(AttachedBindingMember.CreateMember<StringElement, string>(nameof(StringElement.Value),
                (info, element) => element.Value,
                (info, element, arg3) =>
                {
                    element.Value = arg3;
                    element.Reload();
                }));
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.StringElement.TappedEvent,
                (info, element, arg3) =>
                {
                    var weakWrapper = arg3.ToWeakWrapper();
                    IDisposable unsubscriber = null;
                    Action action = () =>
                    {
                        if (!weakWrapper.EventListener.TryHandle(weakWrapper.EventListener, EventArgs.Empty))
                            unsubscriber.Dispose();
                    };
                    unsubscriber = WeakActionToken.Create(element, action,
                        (stringElement, nsAction) => stringElement.Tapped -= nsAction);
                    element.Tapped += action;
                    return unsubscriber;
                }));
        }
        private static void Register(IBindingMemberProvider memberProvider)
        {
            BindingServiceProvider.ResourceResolver.AddType("UITextFieldViewMode", typeof(UITextFieldViewMode));
            RegisterTableViewMembers(memberProvider);
            RegisterCollectionViewMembers(memberProvider);
            RegisterDialogMembers(memberProvider);

            //Object
            memberProvider.Register(AttachedBindingMember.CreateMember <object, object>(AttachedMemberConstants.ItemsSource,
                                                                                        GetObjectItemsSource, SetObjectItemsSource, ObserveObjectItemsSource));

            memberProvider.Register(CollectionViewManagerMember);
            memberProvider.Register(ContentViewManagerMember);
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <object, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplate));

            //UIView
            memberProvider.Register(AttachedBindingMember.CreateMember <UIView, object>(AttachedMemberConstants.Parent,
                                                                                        (info, view) => ParentObserver.GetOrAdd(view).Parent, null, (info, view, arg3) => ParentObserver.GetOrAdd(view).AddWithUnsubscriber(arg3)));
            memberProvider.Register(AttachedBindingMember.CreateMember <UIView, object>(AttachedMemberConstants.FindByNameMethod, FindViewByName));
            memberProvider.Register(ContentMember);
            memberProvider.Register(ContentTemplateMember);
            memberProvider.Register(AttachedBindingMember.CreateMember <UIView, bool>("Visible", (info, view) => !view.Hidden, (info, view, arg3) => view.Hidden = !arg3));

            //UIButton
            memberProvider.Register(AttachedBindingMember.CreateMember <UIButton, string>("Title",
                                                                                          (info, button) => button.CurrentTitle,
                                                                                          (info, button, arg3) => button.SetTitle(arg3, UIControlState.Normal)));

            //UIDatePicker
            memberProvider.Register(AttachedBindingMember.CreateMember <UIDatePicker, DateTime>("Date",
                                                                                                (info, picker) => picker.Date, (info, picker, arg3) => picker.Date = arg3, "ValueChanged"));

            //UISwitch
            memberProvider.Register(AttachedBindingMember.CreateMember <UISwitch, bool>("On",
                                                                                        (info, picker) => picker.On, (info, picker, arg3) => picker.On = arg3, "ValueChanged"));

            //UIControl
            var clickMember = memberProvider.GetBindingMember(typeof(UIControl), "TouchUpInside", true, false);

            if (clickMember != null)
            {
                memberProvider.Register(typeof(UIControl), "Click", clickMember, true);
            }

            //UITextField
            NSNotificationCenter.DefaultCenter.AddObserver(UITextField.TextFieldTextDidChangeNotification, TextDidChangeNotification);
            memberProvider.Register(AttachedBindingMember.CreateEvent <UITextField>("TextChanged", SetTextFieldTextChanged));

            //UITextView
            NSNotificationCenter.DefaultCenter.AddObserver(UITextView.TextDidChangeNotification, TextDidChangeNotification);
            memberProvider.Register(AttachedBindingMember.CreateEvent <UITextView>("TextChanged", SetTextFieldTextChanged));

            //UILabel
            memberProvider.Register(AttachedBindingMember.CreateMember <UILabel, string>("TextSizeToFit",
                                                                                         (info, label) => label.Text,
                                                                                         (info, label, arg3) =>
            {
                label.Text = arg3;
                label.SizeToFit();
            }));

            //UITabBarController
            memberProvider.Register(TabBarSelectedItemMember);
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <UITabBarController, IEnumerable>(AttachedMemberConstants.ItemsSource, TabBarItemsSourceChanged));

            //UIViewController
            BindingServiceProvider.BindingMemberPriorities[ToolbarItemTemplate] = 1;
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <UIViewController, IEnumerable>("ToolbarItemsSource", ToolbarItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <UIViewController, IDataTemplateSelector>(ToolbarItemTemplate));
            memberProvider.Register(AttachedBindingMember.CreateMember <UIViewController, string>("Title",
                                                                                                  (info, controller) => controller.Title,
                                                                                                  (info, controller, arg3) => controller.Title = arg3 ?? string.Empty));
            memberProvider.Register(
                AttachedBindingMember.CreateMember <UIViewController, object>(AttachedMemberConstants.Parent,
                                                                              (info, controller) =>
            {
                var parent = BindingExtensions.AttachedParentMember.GetValue(controller, null);
                if (parent == null)
                {
                    parent = controller.ParentViewController ?? controller.PresentingViewController;
                }
                return(parent);
            },
                                                                              (info, controller, arg3) => BindingExtensions.AttachedParentMember.SetValue(controller, arg3),
                                                                              (info, controller, arg3) => BindingExtensions.AttachedParentMember.TryObserve(controller, arg3)));

            //UISplitViewController
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <UISplitViewController, IEnumerable>(AttachedMemberConstants.ItemsSource, SplitViewControllerItemsSourceChanged));

            //UIToolbar
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <UIToolbar, IEnumerable>(AttachedMemberConstants.ItemsSource, ToolbarItemsSourceChanged));

            //UIPickerView
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <UIPickerView, IEnumerable>(AttachedMemberConstants.ItemsSource, PickerViewItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <UIPickerView, string>("DisplayMemberPath", PickerViewDisplayMemberPathChangedChanged));
            memberProvider.Register(
                AttachedBindingMember.CreateMember <UIPickerView, object>(AttachedMemberConstants.SelectedItem,
                                                                          (info, view) => GetOrAddPickerViewModel(view).SelectedItem,
                                                                          (info, view, arg3) => GetOrAddPickerViewModel(view).SelectedItem = arg3, (info, view, arg3) =>
            {
                var viewModel = GetOrAddPickerViewModel(view);
                return(BindingServiceProvider.WeakEventManager.TrySubscribe(viewModel, "SelectedItemChanged", arg3));
            }));
        }
Exemple #12
0
        private static void Register(IBindingMemberProvider memberProvider)
        {
            BindingServiceProvider.ResourceResolver.AddType(typeof(UITextFieldViewMode));
            RegisterTableViewMembers(memberProvider);
            RegisterCollectionViewMembers(memberProvider);
            RegisterDialogMembers(memberProvider);
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIBarButtonItem.ClickEvent);
            BindingBuilderExtensions.RegisterDefaultBindingMember <UISearchBar>(() => t => t.Text);
            BindingBuilderExtensions.RegisterDefaultBindingMember <UISlider>(() => t => t.Value);
            BindingBuilderExtensions.RegisterDefaultBindingMember <UIProgressView>(() => t => t.Progress);

            //Object
            var itemsSourceMember         = AttachedBindingMember.CreateAutoProperty <object, IEnumerable>(AttachedMemberConstants.ItemsSource, ObjectItemsSourceChanged);
            var defaultMemberRegistration = new DefaultAttachedMemberRegistration <IEnumerable>(itemsSourceMember);

            memberProvider.Register(defaultMemberRegistration.ToAttachedBindingMember <object>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <object, ICollectionViewManager>(AttachedMembers.UIView.CollectionViewManager.Path));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <object, IContentViewManager>(AttachedMembers.UIView.ContentViewManager.Path));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(ItemsSourceGeneratorBase.MemberDescriptor,
                                                                             (o, args) =>
            {
                IEnumerable itemsSource = null;
                if (args.OldValue != null)
                {
                    itemsSource = args.OldValue.ItemsSource;
                    args.OldValue.SetItemsSource(null);
                }
                if (args.NewValue != null)
                {
                    args.NewValue.SetItemsSource(itemsSource);
                }
            }));

            var itemTemplateMember = AttachedBindingMember.CreateAutoProperty <object, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplateSelector);

            memberProvider.Register(itemTemplateMember);
            memberProvider.Register(typeof(object), AttachedMemberConstants.ItemTemplate, itemTemplateMember, true);

            //UIView
            memberProvider.Register(AttachedBindingMember.CreateMember <UIView, object>(AttachedMemberConstants.Parent,
                                                                                        (info, view) => ParentObserver.GetOrAdd(view).Parent, (info, view, arg3) => ParentObserver.GetOrAdd(view).Parent = arg3, (info, view, arg3) => ParentObserver.GetOrAdd(view).AddWithUnsubscriber(arg3)));
            memberProvider.Register(AttachedBindingMember.CreateMember <UIView, object>(AttachedMemberConstants.FindByNameMethod, FindViewByName));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.Content, ContentChanged));
            var member = AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.ContentTemplateSelector, ContentTemplateChanged);

            memberProvider.Register(member);
            memberProvider.Register(typeof(UIView), AttachedMemberConstants.ContentTemplate, member, true);
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIView.Visible, (info, view) => !view.Hidden, (info, view, arg3) => view.Hidden = !arg3));

            //UISegmentedControl
            BindingBuilderExtensions.RegisterDefaultBindingMember <UISegmentedControl>(() => t => t.SelectedSegment);
            memberProvider.Register(AttachedBindingMember.CreateMember <UISegmentedControl, int>("SelectedSegment",
                                                                                                 (info, control) => (int)control.SelectedSegment,
                                                                                                 (info, control, arg3) => control.SelectedSegment = arg3, "ValueChanged"));

            //UIButton
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIControl.ClickEvent.Override <UIButton>());
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIButton.Title,
                                                                       (info, button) => button.CurrentTitle,
                                                                       (info, button, arg3) => button.SetTitle(arg3, button.State)));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIButton.State,
                                                                       (info, button) => button.State,
                                                                       (info, button, arg3) => button.SetTitle(button.CurrentTitle, arg3)));

            //UIDatePicker
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIDatePicker.Date);
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIDatePicker.Date,
                                                                       (info, picker) => NSDateToDateTime(picker.Date), (info, picker, arg3) => picker.Date = DateTimeToNSDate(arg3), "ValueChanged"));

            //UISwitch
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UISwitch.On);
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UISwitch.On,
                                                                       (info, picker) => picker.On, (info, picker, arg3) => picker.On = arg3, "ValueChanged"));

            //UIControl
            var clickMember = memberProvider.GetBindingMember(typeof(UIControl), "TouchUpInside", true, false);

            if (clickMember != null)
            {
                memberProvider.Register(typeof(UIControl), "Click", clickMember, true);
            }

            //UITextField
            BindingBuilderExtensions.RegisterDefaultBindingMember <UITextField>(() => t => t.Text);
            NSNotificationCenter.DefaultCenter.AddObserver(UITextField.TextFieldTextDidChangeNotification, TextDidChangeNotification);
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UITextField.TextChangedEvent, SetTextFieldTextChanged));

            //UITextView
            BindingBuilderExtensions.RegisterDefaultBindingMember <UITextView>(() => t => t.Text);
            NSNotificationCenter.DefaultCenter.AddObserver(UITextView.TextDidChangeNotification, TextDidChangeNotification);
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UITextView.TextChangedEvent, SetTextFieldTextChanged));

            //UILabel
            BindingBuilderExtensions.RegisterDefaultBindingMember <UILabel>(() => t => t.Text);
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UILabel.TextSizeToFit,
                                                                       (info, label) => label.Text,
                                                                       (info, label, arg3) =>
            {
                label.Text = arg3;
                label.SizeToFit();
            }));

            //UIViewController
            BindingServiceProvider.BindingMemberPriorities["ToolbarItemTemplate"] = BindingServiceProvider.TemplateMemberPriority;
            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.UIViewController.ToolbarItemTemplateSelector] = BindingServiceProvider.TemplateMemberPriority;
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIViewController.ToastTemplateSelector));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIViewController.ToolbarItemsSource, ToolbarItemsSourceChanged));
            var templateMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIViewController.ToolbarItemTemplateSelector);

            memberProvider.Register(templateMember);
            memberProvider.Register(typeof(UIViewController), "ToolbarItemTemplate", templateMember, true);
            memberProvider.Register(AttachedBindingMember.CreateMember <UIViewController, string>("Title",
                                                                                                  (info, controller) => controller.Title,
                                                                                                  (info, controller, arg3) => controller.Title = arg3 ?? string.Empty));
            memberProvider.Register(AttachedBindingMember.CreateMember <UIViewController, object>(AttachedMemberConstants.ParentExplicit,
                                                                                                  (info, controller) => controller.ParentViewController ?? controller.PresentingViewController ?? controller.SplitViewController, null));

            //UITabBarController
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UITabBarController.ItemsSource);
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITabBarController.SelectedItem, TabBarSelectedItemChanged, TabBarSelectedItemAttached));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITabBarController.ItemsSource, TabBarItemsSourceChanged));

            //UISplitViewController
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(AttachedMembers.UISplitViewController.MasterView,
                                                                                 (info, controller) =>
            {
                if (controller.ViewControllers.Length == 2)
                {
                    return(controller.ViewControllers[0]);
                }
                return(null);
            }, (info, controller, arg3) =>
            {
                UpdateMasterDetailController(controller, arg3, true);
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(AttachedMembers.UISplitViewController.DetailView,
                                                                                 (info, controller) =>
            {
                if (controller.ViewControllers.Length == 2)
                {
                    return(controller.ViewControllers[1]);
                }
                return(null);
            }, (info, controller, arg3) =>
            {
                UpdateMasterDetailController(controller, arg3, false);
                return(true);
            }));

            //UIToolbar
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIView.ItemsSource.Override <UIToolbar>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.ItemsSource.Override <UIToolbar>(), ToolbarItemsSourceChanged));

            //UIPickerView
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIView.ItemsSource.Override <UIPickerView>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.ItemsSource.Override <UIPickerView>(), PickerViewItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIPickerView.DisplayMemberPath, PickerViewDisplayMemberPathChangedChanged));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIPickerView.SelectedItem,
                                                                       (info, view) => GetOrAddPickerViewModel(view).SelectedItem,
                                                                       (info, view, arg3) => GetOrAddPickerViewModel(view).SelectedItem = arg3, (info, view, arg3) =>
            {
                var viewModel = GetOrAddPickerViewModel(view);
                return(BindingServiceProvider.WeakEventManager.TrySubscribe(viewModel, "SelectedItemChanged", arg3));
            }));
        }
        private static void Register(IBindingMemberProvider memberProvider)
        {
            BindingServiceProvider.ResourceResolver.AddType(typeof(UITextFieldViewMode));
            RegisterTableViewMembers(memberProvider);
            RegisterCollectionViewMembers(memberProvider);
            RegisterDialogMembers(memberProvider);
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIBarButtonItem.ClickEvent);
            BindingBuilderExtensions.RegisterDefaultBindingMember<UISearchBar>(nameof(UISearchBar.Text));
            BindingBuilderExtensions.RegisterDefaultBindingMember<UISlider>(nameof(UISlider.Value));
            BindingBuilderExtensions.RegisterDefaultBindingMember<UIProgressView>(nameof(UIProgressView.Progress));

            //Object
            var itemsSourceMember = AttachedBindingMember.CreateAutoProperty<object, IEnumerable>(AttachedMemberConstants.ItemsSource, ObjectItemsSourceChanged);
            var defaultMemberRegistration = new DefaultAttachedMemberRegistration<IEnumerable>(itemsSourceMember);
            memberProvider.Register(defaultMemberRegistration.ToAttachedBindingMember<object>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty<object, ICollectionViewManager>(AttachedMembers.UIView.CollectionViewManager.Path));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty<object, IContentViewManager>(AttachedMembers.UIView.ContentViewManager.Path));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(ItemsSourceGeneratorBase.MemberDescriptor,
                (o, args) =>
                {
                    IEnumerable itemsSource = null;
                    if (args.OldValue != null)
                    {
                        itemsSource = args.OldValue.ItemsSource;
                        args.OldValue.SetItemsSource(null);
                    }
                    if (args.NewValue != null)
                        args.NewValue.SetItemsSource(itemsSource);
                }));

            var itemTemplateMember = AttachedBindingMember.CreateAutoProperty<object, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplateSelector);
            memberProvider.Register(itemTemplateMember);
            memberProvider.Register(typeof(object), AttachedMemberConstants.ItemTemplate, itemTemplateMember, true);

            //UIView
            memberProvider.Register(AttachedBindingMember.CreateMember<UIView, object>(AttachedMemberConstants.Parent,
                (info, view) => ParentObserver.GetOrAdd(view).Parent, (info, view, arg3) => ParentObserver.GetOrAdd(view).Parent = arg3, (info, view, arg3) => ParentObserver.GetOrAdd(view).AddWithUnsubscriber(arg3)));
            memberProvider.Register(AttachedBindingMember.CreateMember<UIView, object>(AttachedMemberConstants.FindByNameMethod, FindViewByName));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.Content, ContentChanged));
            var member = AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.ContentTemplateSelector, ContentTemplateChanged);
            memberProvider.Register(member);
            memberProvider.Register(typeof(UIView), AttachedMemberConstants.ContentTemplate, member, true);
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIView.Visible, (info, view) => !view.Hidden, (info, view, arg3) => view.Hidden = !arg3));

            //UISegmentedControl
            BindingBuilderExtensions.RegisterDefaultBindingMember<UISegmentedControl>(nameof(UISegmentedControl.SelectedSegment));
            memberProvider.Register(AttachedBindingMember.CreateMember<UISegmentedControl, int>(nameof(UISegmentedControl.SelectedSegment),
                (info, control) => (int)control.SelectedSegment,
                (info, control, arg3) => control.SelectedSegment = arg3, nameof(UISegmentedControl.ValueChanged)));

            //UIButton
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIControl.ClickEvent.Override<UIButton>());
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIButton.Title,
                (info, button) => button.CurrentTitle,
                (info, button, arg3) => button.SetTitle(arg3, button.State)));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIButton.State,
                (info, button) => button.State,
                (info, button, arg3) => button.SetTitle(button.CurrentTitle, arg3)));

            //UIDatePicker
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIDatePicker.Date);
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIDatePicker.Date,
                (info, picker) => NSDateToDateTime(picker.Date), (info, picker, arg3) => picker.Date = DateTimeToNSDate(arg3), nameof(UIDatePicker.ValueChanged)));

            //UISwitch
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UISwitch.On);
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UISwitch.On,
                (info, picker) => picker.On, (info, picker, arg3) => picker.On = arg3, nameof(UISwitch.ValueChanged)));

            //UIControl
            var clickMember = memberProvider.GetBindingMember(typeof(UIControl), nameof(UIControl.TouchUpInside), true, false);
            if (clickMember != null)
                memberProvider.Register(typeof(UIControl), "Click", clickMember, true);

            //UITextField
            BindingBuilderExtensions.RegisterDefaultBindingMember<UITextField>(nameof(UITextField.Text));
            NSNotificationCenter.DefaultCenter.AddObserver(UITextField.TextFieldTextDidChangeNotification, TextDidChangeNotification);
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UITextField.TextChangedEvent, SetTextFieldTextChanged));

            //UITextView
            BindingBuilderExtensions.RegisterDefaultBindingMember<UITextView>(nameof(UITextView.Text));
            NSNotificationCenter.DefaultCenter.AddObserver(UITextView.TextDidChangeNotification, TextDidChangeNotification);
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UITextView.TextChangedEvent, SetTextFieldTextChanged));

            //UILabel
            BindingBuilderExtensions.RegisterDefaultBindingMember<UILabel>(nameof(UILabel.Text));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UILabel.TextSizeToFit,
                (info, label) => label.Text,
                (info, label, arg3) =>
                {
                    label.Text = arg3;
                    label.SizeToFit();
                }));

            //UIViewController
            BindingServiceProvider.BindingMemberPriorities["ToolbarItemTemplate"] = BindingServiceProvider.TemplateMemberPriority;
            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.UIViewController.ToolbarItemTemplateSelector] = BindingServiceProvider.TemplateMemberPriority;
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIViewController.ToastTemplateSelector));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIViewController.ToolbarItemsSource, ToolbarItemsSourceChanged));
            var templateMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIViewController.ToolbarItemTemplateSelector);
            memberProvider.Register(templateMember);
            memberProvider.Register(typeof(UIViewController), "ToolbarItemTemplate", templateMember, true);
            memberProvider.Register(AttachedBindingMember.CreateMember<UIViewController, string>(nameof(UIViewController.Title),
                (info, controller) => controller.Title,
                (info, controller, arg3) => controller.Title = arg3 ?? string.Empty));
            memberProvider.Register(AttachedBindingMember.CreateMember<UIViewController, object>(AttachedMemberConstants.ParentExplicit,
                    (info, controller) => controller.ParentViewController ?? controller.PresentingViewController ?? controller.SplitViewController, null));

            //UITabBarController
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UITabBarController.ItemsSource);
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITabBarController.SelectedItem, TabBarSelectedItemChanged, TabBarSelectedItemAttached));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITabBarController.ItemsSource, TabBarItemsSourceChanged));

            //UISplitViewController
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(AttachedMembers.UISplitViewController.MasterView,
                (info, controller) =>
                {
                    if (controller.ViewControllers.Length == 2)
                        return controller.ViewControllers[0];
                    return null;
                }, (info, controller, arg3) =>
                {
                    UpdateMasterDetailController(controller, arg3, true);
                    return true;
                }));
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(AttachedMembers.UISplitViewController.DetailView,
                (info, controller) =>
                {
                    if (controller.ViewControllers.Length == 2)
                        return controller.ViewControllers[1];
                    return null;
                }, (info, controller, arg3) =>
                {
                    UpdateMasterDetailController(controller, arg3, false);
                    return true;
                }));

            //UIToolbar
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIView.ItemsSource.Override<UIToolbar>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.ItemsSource.Override<UIToolbar>(), ToolbarItemsSourceChanged));

            //UIPickerView
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIView.ItemsSource.Override<UIPickerView>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.ItemsSource.Override<UIPickerView>(), PickerViewItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIPickerView.DisplayMemberPath, PickerViewDisplayMemberPathChangedChanged));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UIPickerView.SelectedItem,
                    (info, view) => GetOrAddPickerViewModel(view).SelectedItem,
                    (info, view, arg3) => GetOrAddPickerViewModel(view).SelectedItem = arg3, (info, view, arg3) =>
                    {
                        var viewModel = GetOrAddPickerViewModel(view);
                        return BindingServiceProvider.WeakEventManager.TrySubscribe(viewModel, nameof(MvvmPickerViewModel.SelectedItemChanged), arg3);
                    }));
        }
        private static void Register([NotNull] IBindingMemberProvider memberProvider)
        {
            Should.NotBeNull(memberProvider, "memberProvider");

            //Object
            memberProvider.Register(AttachedBindingMember.CreateMember <object, object>(AttachedMemberConstants.ItemsSource,
                                                                                        GetObjectItemsSource, SetObjectItemsSource, ObserveObjectItemsSource));

            memberProvider.Register(CollectionViewManagerMember);
            memberProvider.Register(ContentViewManagerMember);
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <object, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplate));

            //Control
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Control, object>(AttachedMemberConstants.FindByNameMethod, FindByNameControlMember));
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Control, bool>(AttachedMemberConstants.Focused, (info, control) => control.Focused, null, "LostFocus"));

            //Registering parent member as attached to avoid use the BindingExtensions.AttachedParentMember property.
            var parentMember = memberProvider.GetBindingMember(typeof(Control), AttachedMemberConstants.Parent, true, false);

            if (parentMember != null)
            {
                memberProvider.Register(typeof(Control), parentMember, true);
            }

            memberProvider.Register(ContentMember);
            memberProvider.Register(ContentTemplateMember);

            //DateTimePicker
            memberProvider.Register(AttachedBindingMember.CreateMember <DateTimePicker, DateTime>("Value",
                                                                                                  (info, picker) => picker.Value,
                                                                                                  (info, picker, value) =>
            {
                if (value < picker.MinDate)
                {
                    picker.Value = picker.MinDate;
                }
                else if (value > picker.MaxDate)
                {
                    picker.Value = picker.MaxDate;
                }
                else
                {
                    picker.Value = value;
                }
            }, "ValueChanged"));

            //ToolStripItem
            memberProvider.Register(AttachedBindingMember.CreateMember <ToolStripItem, object>(AttachedMemberConstants.Parent,
                                                                                               GetParentToolStripItem, null, ObserveParentMemberToolStripItem));
            memberProvider.Register(AttachedBindingMember.CreateMember <ToolStripItem, object>(AttachedMemberConstants.FindByNameMethod,
                                                                                               FindByNameMemberToolStripItem));

            //TabControl
            memberProvider.Register(AttachedBindingMember.CreateMember <TabControl, object>(AttachedMemberConstants.SelectedItem,
                                                                                            GetSelectedItemTabControl, SetSelectedItemTabControl, "Selected"));

            //ComboBox
            memberProvider.Register(
                AttachedBindingMember.CreateMember <ComboBox, object>(AttachedMemberConstants.ItemsSource,
                                                                      (info, box) => box.DataSource,
                                                                      (info, box, value) => box.DataSource = value, "DataSourceChanged"));
            memberProvider.Register(
                AttachedBindingMember.CreateMember <ComboBox, object>(AttachedMemberConstants.SelectedItem,
                                                                      (info, box) => box.SelectedItem, (info, box, value) => box.SelectedItem = value,
                                                                      "SelectedIndexChanged"));

            //DataGridView
            memberProvider.Register(
                AttachedBindingMember.CreateMember <DataGridView, object>(AttachedMemberConstants.ItemsSource,
                                                                          (info, view) => view.DataSource, (info, view, value) =>
            {
                view.DataSource = value;
                view.Refresh();
            }, "DataSourceChanged"));
            memberProvider.Register(
                AttachedBindingMember.CreateMember <DataGridView, object>(AttachedMemberConstants.SelectedItem,
                                                                          GetSelectedItemDataGridView, SetSelectedItemDataGridView, "CurrentCellChanged"));
        }
        private static void Register(IBindingMemberProvider memberProvider)
        {
            BindingBuilderExtensions.RegisterDefaultBindingMember<Button>(nameof(Button.Click));
            BindingBuilderExtensions.RegisterDefaultBindingMember<TextBox>(nameof(TextBox.Text));
            BindingBuilderExtensions.RegisterDefaultBindingMember<Label>(nameof(Label.Text));
            BindingBuilderExtensions.RegisterDefaultBindingMember<CheckBox>(nameof(CheckBox.Checked));
            BindingBuilderExtensions.RegisterDefaultBindingMember<ProgressBar>(nameof(ProgressBar.Value));

            //Object
            var itemsSourceMember = AttachedBindingMember.CreateAutoProperty<object, IEnumerable>(AttachedMemberConstants.ItemsSource, ObjectItemsSourceChanged);
            var defaultMemberRegistration = new DefaultAttachedMemberRegistration<IEnumerable>(itemsSourceMember);
            memberProvider.Register(defaultMemberRegistration.ToAttachedBindingMember<object>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Object.CollectionViewManager));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty<object, IContentViewManager>(AttachedMembers.Control.ContentViewManager.Path));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(ItemsSourceGeneratorBase.MemberDescriptor,
                (o, args) =>
                {
                    IEnumerable itemsSource = null;
                    if (args.OldValue != null)
                    {
                        itemsSource = args.OldValue.ItemsSource;
                        args.OldValue.SetItemsSource(null);
                    }
                    if (args.NewValue != null)
                        args.NewValue.SetItemsSource(itemsSource);
                }));

            var itemTemplateMember = AttachedBindingMember.CreateAutoProperty<object, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplateSelector);
            memberProvider.Register(itemTemplateMember);
            memberProvider.Register(typeof(object), AttachedMemberConstants.ItemTemplate, itemTemplateMember, true);

            //Form
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Form.ToastTemplateSelector));

            //Control
            var sizeChanged = memberProvider.GetBindingMember(typeof(Control), nameof(Control.SizeChanged), true, false);
            if (sizeChanged != null)
            {
                memberProvider.Register(typeof(Control), "WidthChanged", sizeChanged, true);
                memberProvider.Register(typeof(Control), "HeightChanged", sizeChanged, true);
            }
            memberProvider.Register(AttachedBindingMember
                .CreateMember<Control, object>(AttachedMemberConstants.FindByNameMethod, FindByNameControlMember));
            memberProvider.Register(AttachedBindingMember
                .CreateMember<Control, bool>(AttachedMemberConstants.Focused, (info, control) => control.Focused,
                    (info, control, arg3) =>
                    {
                        if (arg3)
                            control.Focus();
                    }, nameof(Control.LostFocus)));

            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Control.Content, ContentChanged));
            var contenMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.Control.ContentTemplateSelector, ContentTemplateChanged);
            memberProvider.Register(contenMember);
            memberProvider.Register(typeof(Control), AttachedMemberConstants.ContentTemplate, contenMember, true);

            //DateTimePicker
            BindingBuilderExtensions.RegisterDefaultBindingMember<DateTimePicker>(nameof(DateTimePicker.Value));
            memberProvider.Register(AttachedBindingMember.CreateMember<DateTimePicker, DateTime>(nameof(DateTimePicker.Value),
                (info, picker) => picker.Value,
                (info, picker, value) =>
                {
                    if (value < picker.MinDate)
                        picker.Value = picker.MinDate;
                    else if (value > picker.MaxDate)
                        picker.Value = picker.MaxDate;
                    else
                        picker.Value = value;
                }, nameof(DateTimePicker.ValueChanged)));

            //ToolStripItem
            BindingBuilderExtensions.RegisterDefaultBindingMember<ToolStripButton>(nameof(ToolStripButton.Click));
            BindingBuilderExtensions.RegisterDefaultBindingMember<ToolStripMenuItem>(nameof(ToolStripMenuItem.Click));
            BindingBuilderExtensions.RegisterDefaultBindingMember<ToolStripItem>(nameof(ToolStripItem.Text));
            memberProvider.Register(AttachedBindingMember.CreateMember<ToolStripItem, object>(AttachedMemberConstants.ParentExplicit,
                    GetParentToolStripItem, null, ObserveParentMemberToolStripItem));
            memberProvider.Register(AttachedBindingMember.CreateMember<ToolStripItem, object>(AttachedMemberConstants.FindByNameMethod,
                    FindByNameMemberToolStripItem));

            //TabControl
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.Object.ItemsSource.Override<TabControl>());
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.TabControl.SelectedItem,
                GetSelectedItemTabControl, SetSelectedItemTabControl, nameof(TabControl.Selected)));

            //ComboBox
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.Object.ItemsSource.Override<ComboBox>());
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.Object.ItemsSource.Override<ComboBox>(),
                    (info, box) => box.DataSource as IEnumerable,
                    (info, box, value) => box.DataSource = value, nameof(ComboBox.DataSourceChanged)));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.ComboBox.SelectedItem,
                    (info, box) => box.SelectedItem, (info, box, value) => box.SelectedItem = value, nameof(ComboBox.SelectedIndexChanged)));

            //DataGridView
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.Object.ItemsSource.Override<DataGridView>());
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.Object.ItemsSource.Override<DataGridView>(),
                    (info, view) => view.DataSource as IEnumerable, (info, view, value) =>
                    {
                        view.DataSource = value;
                        view.Refresh();
                    }, nameof(DataGridView.DataSourceChanged)));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.DataGridView.SelectedItem,
                    GetSelectedItemDataGridView, SetSelectedItemDataGridView, (info, view, arg3) =>
                    {
                        arg3 = arg3.ToWeakEventListener();
                        EventHandler handler = null;
                        handler = (sender, args) =>
                        {
                            var gridView = (DataGridView)sender;
                            Action<DataGridView, IEventListener, EventHandler> action =
                                (dataGridView, listener, eventHandler) =>
                                {
                                    if (!listener.TryHandle(dataGridView, EventArgs.Empty))
                                        dataGridView.CurrentCellChanged -= eventHandler;
                                };
                            //To prevent this exception 'Operation not valid because it results in a reentrant call to the SetCurrentCellAddressCore function'
                            gridView.BeginInvoke(action, gridView, arg3, handler);
                        };
                        view.CurrentCellChanged += handler;
                        return WeakActionToken.Create(view, handler,
                            (gridView, eventHandler) => gridView.CurrentCellChanged -= eventHandler);
                    }));
        }
Exemple #16
0
        private static void Register([NotNull] IBindingMemberProvider memberProvider)
        {
            Should.NotBeNull(memberProvider, "memberProvider");
            RegisterMenuMembers(memberProvider);
            RegisterViewMembers(memberProvider);
#if !API8
            RegisterActionBarMembers(memberProvider);
            //Dialog
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <Dialog, object>("Title",
                                                                                              (dialog, args) => dialog.SetTitle(args.NewValue.ToStringSafe())));
#endif
            //Activity
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <Activity, string>("Title",
                                                                                                (activity, args) => activity.Title = args.NewValue, getDefaultValue: (activity, info) => activity.Title));
            //to suppress message about parent property.
            memberProvider.Register(AttachedBindingMember.CreateMember <Activity, object>(AttachedMemberConstants.Parent, (info, activity) => null, null));

            //CompoundButton
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <CompoundButton, bool>("Checked", (info, btn) => btn.Checked,
                                                                         (info, btn, value) => btn.Checked = value, "CheckedChange"));

            //RatingBar
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <RatingBar, float>("Rating", (info, btn) => btn.Rating,
                                                                     (info, btn, value) => btn.Rating = value, "RatingBarChange"));

            //AdapterView
            _rawAdapterMember = memberProvider.GetBindingMember(typeof(AdapterView), "RawAdapter", false, true);
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <AdapterView, int?>(AttachedMemberNames.DropDownItemTemplate,
                                                                            ViewGroupTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <AdapterView, int?>(AttachedMemberNames.DropDownItemTemplateSelector,
                                                                            ViewGroupTemplateChanged));
            memberProvider.Register(AdapterViewSelectedItemMember);
            memberProvider.Register(AdapterViewSelectedPositionMember);
            memberProvider.Register(ScrollToSelectedItemMember);

            //ViewGroup
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ViewGroup, IEnumerable>(AttachedMemberConstants.ItemsSource, ViewGroupItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ViewGroup, int?>(AttachedMemberConstants.ItemTemplate, ViewGroupTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ViewGroup, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplateSelector, ViewGroupTemplateChanged));

            memberProvider.Register(ContentMember);
            memberProvider.Register(ContentTemplateIdMember);
            memberProvider.Register(ContentTemplateSelectorMember);
#if !API8
            memberProvider.Register(AddToBackStackMember);
#endif

            //TabHost
            memberProvider.Register(TabHostSelectedItemMember);
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, IEnumerable>(AttachedMemberConstants.ItemsSource, TabHostItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, int?>(AttachedMemberConstants.ItemTemplate, TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplateSelector,
                                                                                         TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, int?>(AttachedMemberConstants.ContentTemplate, TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <TabHost, IDataTemplateSelector>(AttachedMemberConstants.ContentTemplateSelector,
                                                                                         TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <TabHost.TabSpec, string>("Title",
                                                                                                       (spec, args) => spec.SetIndicator(args.NewValue)));


            //DatePicker
            var selectedDateMember = AttachedBindingMember.CreateMember <DatePicker, DateTime>("SelectedDate",
                                                                                               (info, picker) => picker.DateTime, (info, picker, value) => picker.DateTime = value,
                                                                                               ObserveSelectedDate, SelectedDateMemberAttached);
            memberProvider.Register(selectedDateMember);
            memberProvider.Register("DateTime", selectedDateMember);

            //TimePicker
            var selectedTimeMember = AttachedBindingMember.CreateMember <TimePicker, TimeSpan>("SelectedTime", GetTimePickerValue, SetTimePickerValue, ObserveTimePickerValue);
            memberProvider.Register(selectedTimeMember);
            memberProvider.Register("Value", selectedTimeMember);

            //ImageView
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <ImageView, object>("ImageSource",
                                                                                                 (view, args) =>
            {
                if (args.NewValue == null)
                {
                    view.SetImageBitmap(null);
                    return;
                }
                var bitmap = args.NewValue as Bitmap;
                if (bitmap != null)
                {
                    view.SetImageBitmap(bitmap);
                    return;
                }
                var drawable = args.NewValue as Drawable;
                if (drawable != null)
                {
                    view.SetImageDrawable(drawable);
                    return;
                }
                var uri = args.NewValue as Android.Net.Uri;
                if (uri != null)
                {
                    view.SetImageURI(uri);
                    return;
                }
                view.SetImageResource((int)args.NewValue);
            }));
        }
        private static void Register([NotNull] IBindingMemberProvider memberProvider)
        {
            Should.NotBeNull(memberProvider, "memberProvider");
            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.Object.StableIdProvider] = BindingServiceProvider.TemplateMemberPriority - 1;
            RegisterMenuMembers(memberProvider);
            RegisterViewMembers(memberProvider);
            RegisterPreferenceMembers(memberProvider);
            BindingBuilderExtensions.RegisterDefaultBindingMember <Button>("Click");
            BindingBuilderExtensions.RegisterDefaultBindingMember <TextView>(() => v => v.Text);
            BindingBuilderExtensions.RegisterDefaultBindingMember <EditText>(() => v => v.Text);
            BindingBuilderExtensions.RegisterDefaultBindingMember <CheckBox>(() => v => v.Checked);
            BindingBuilderExtensions.RegisterDefaultBindingMember <CompoundButton>(() => v => v.Checked);
            BindingBuilderExtensions.RegisterDefaultBindingMember <SeekBar>(() => v => v.Progress);

            //Object
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Object.StableIdProvider));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <Object, ICollectionViewManager>(AttachedMembers.ViewGroup.CollectionViewManager.Path));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <Object, IContentViewManager>(AttachedMembers.ViewGroup.ContentViewManager.Path));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(ItemsSourceGeneratorBase.MemberDescriptor,
                                                                             (o, args) =>
            {
                IEnumerable itemsSource = null;
                if (args.OldValue != null)
                {
                    itemsSource = args.OldValue.ItemsSource;
                    args.OldValue.SetItemsSource(null);
                }
                if (args.NewValue != null)
                {
                    args.NewValue.SetItemsSource(itemsSource);
                }
            }));

            //Dialog
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Dialog.Title,
                                                                             (dialog, args) => dialog.SetTitle(args.NewValue.ToStringSafe())));

            //Activity
            //to suppress message about parent
            memberProvider.Register(AttachedBindingMember.CreateMember <Activity, object>(AttachedMemberConstants.ParentExplicit, (info, activity) => null, null));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <Activity, string>("Title",
                                                                                                (activity, args) => activity.Title = args.NewValue, getDefaultValue: (activity, info) => activity.Title));
            memberProvider.Register(AttachedBindingMember.CreateMember <Activity, object>(AttachedMemberConstants.FindByNameMethod, ActivityFindByNameMember));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Activity.ToastTemplateSelector));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Activity.StartActivityDelegate));

            //RatingBar
            BindingBuilderExtensions.RegisterDefaultBindingMember <RatingBar>(() => r => r.Rating);
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <RatingBar, float>("Rating", (info, btn) => btn.Rating,
                                                                     (info, btn, value) => btn.Rating = value, "RatingBarChange"));

            //AdapterView
            _rawAdapterMember = memberProvider.GetBindingMember(typeof(AdapterView), "RawAdapter", false, true);
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.AdapterView.DropDownItemTemplate, ViewGroupTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.AdapterView.DropDownItemTemplateSelector, ViewGroupTemplateChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.AdapterView.SelectedItem, AdapterViewSelectedItemChanged, AdapterViewSelectedMemberAttached));
            var selectedItemPosMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.AdapterView.SelectedItemPosition,
                                                                                 AdapterViewSelectedItemPositionChanged, AdapterViewSelectedMemberAttached, (view, info) => view.SelectedItemPosition);

            memberProvider.Register(selectedItemPosMember);
            memberProvider.Register(typeof(AdapterView), "SelectedIndex", selectedItemPosMember, true);
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.AdapterView.ScrollToSelectedItem));

            //ViewGroup
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.ViewGroup.ItemsSource);
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ItemsSource, ViewGroupItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ItemTemplate, ViewGroupTemplateChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ItemTemplateSelector, ViewGroupTemplateChanged));

            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.ViewGroup.Content.Override <FrameLayout>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.Content, ContentMemberChanged, ContentMemberAttached));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ContentTemplate, ContentTemplateIdChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ContentTemplateSelector, ContentTemplateSelectorChanged));

            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.DisableHierarchyListener, (@group, args) =>
            {
                @group.SetOnHierarchyChangeListener(args.NewValue ? null : GlobalViewParentListener.Instance);
            }));

            //TabHost
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.TabHost.RestoreSelectedIndex));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.TabHost.SelectedItem, TabHostSelectedItemChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ItemsSource.Override <TabHost>(), TabHostItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ItemTemplate.Override <TabHost>(), TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ItemTemplateSelector.Override <TabHost>(), TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ContentTemplate.Override <TabHost>(), TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ContentTemplateSelector.Override <TabHost>(), TabHostTemplateChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.TabSpec.Title, (spec, args) => spec.SetIndicator(args.NewValue)));

            //AutoCompleteTextView
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.AutoCompleteTextView.ItemTemplate, (view, args) => AutoCompleteTextViewTemplateChanged(view)));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.AutoCompleteTextView.ItemTemplateSelector, (view, args) => AutoCompleteTextViewTemplateChanged(view)));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.AutoCompleteTextView.ItemsSource, AutoCompleteTextViewItemsSourceChanged));

            //DatePicker
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.DatePicker.SelectedDate);
            var selectedDateMember = AttachedBindingMember.CreateMember(AttachedMembers.DatePicker.SelectedDate,
                                                                        (info, picker) => picker.DateTime, (info, picker, value) => picker.DateTime = value,
                                                                        ObserveSelectedDate, SelectedDateMemberAttached);

            memberProvider.Register(selectedDateMember);
            memberProvider.Register("DateTime", selectedDateMember);

            //TimePicker
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.TimePicker.SelectedTime);
            var selectedTimeMember = AttachedBindingMember.CreateMember(AttachedMembers.TimePicker.SelectedTime, GetTimePickerValue, SetTimePickerValue, "TimeChanged");

            memberProvider.Register(selectedTimeMember);
            memberProvider.Register("Value", selectedTimeMember);

            //ImageView
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.ImageView.ImageSource);
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ImageView.ImageSource,
                                                                             (view, args) =>
            {
                if (args.NewValue == null)
                {
                    view.SetImageBitmap(null);
                    return;
                }
                var bitmap = args.NewValue as Bitmap;
                if (bitmap != null)
                {
                    view.SetImageBitmap(bitmap);
                    return;
                }
                var drawable = args.NewValue as Drawable;
                if (drawable != null)
                {
                    view.SetImageDrawable(drawable);
                    return;
                }
                var uri = args.NewValue as global::Android.Net.Uri;
                if (uri != null)
                {
                    view.SetImageURI(uri);
                    return;
                }
                view.SetImageResource((int)args.NewValue);
            }));

            //Toolbar
            if (PlatformExtensions.IsApiGreaterThanOrEqualTo21)
            {
                memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Toolbar.IsActionBar, ToolbarIsActionBarChanged));
                memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Toolbar.MenuTemplate, ToolbarMenuTemplateChanged));
            }
        }
        private static void Register(IBindingMemberProvider memberProvider)
        {
            BindingBuilderExtensions.RegisterDefaultBindingMember <Button>(nameof(Button.Click));
            BindingBuilderExtensions.RegisterDefaultBindingMember <TextBox>(nameof(TextBox.Text));
            BindingBuilderExtensions.RegisterDefaultBindingMember <Label>(nameof(Label.Text));
            BindingBuilderExtensions.RegisterDefaultBindingMember <CheckBox>(nameof(CheckBox.Checked));
            BindingBuilderExtensions.RegisterDefaultBindingMember <ProgressBar>(nameof(ProgressBar.Value));

            //Object
            var itemsSourceMember         = AttachedBindingMember.CreateAutoProperty <object, IEnumerable>(AttachedMemberConstants.ItemsSource, ObjectItemsSourceChanged);
            var defaultMemberRegistration = new DefaultAttachedMemberRegistration <IEnumerable>(itemsSourceMember);

            memberProvider.Register(defaultMemberRegistration.ToAttachedBindingMember <object>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Object.CollectionViewManager));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty <object, IContentViewManager>(AttachedMembers.Control.ContentViewManager.Path));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(ItemsSourceGeneratorBase.MemberDescriptor,
                                                                             (o, args) =>
            {
                IEnumerable itemsSource = null;
                if (args.OldValue != null)
                {
                    itemsSource = args.OldValue.ItemsSource;
                    args.OldValue.SetItemsSource(null);
                }
                args.NewValue?.SetItemsSource(itemsSource);
            }));

            var itemTemplateMember = AttachedBindingMember.CreateAutoProperty <object, IDataTemplateSelector>(AttachedMemberConstants.ItemTemplateSelector);

            memberProvider.Register(itemTemplateMember);
            memberProvider.Register(typeof(object), AttachedMemberConstants.ItemTemplate, itemTemplateMember, true);

            //Form
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Form.ToastTemplateSelector));

            //Control
            var sizeChanged = memberProvider.GetBindingMember(typeof(Control), nameof(Control.SizeChanged), true, false);

            if (sizeChanged != null)
            {
                memberProvider.Register(typeof(Control), "WidthChanged", sizeChanged, true);
                memberProvider.Register(typeof(Control), "HeightChanged", sizeChanged, true);
            }
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Control, object>(AttachedMemberConstants.FindByNameMethod, FindByNameControlMember));
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <Control, bool>(AttachedMemberConstants.Focused, (info, control) => control.Focused,
                                                                  (info, control, arg3) =>
            {
                if (arg3)
                {
                    control.Focus();
                }
            }, nameof(Control.LostFocus)));

            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Control.Content, ContentChanged));
            var contenMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.Control.ContentTemplateSelector, ContentTemplateChanged);

            memberProvider.Register(contenMember);
            memberProvider.Register(typeof(Control), AttachedMemberConstants.ContentTemplate, contenMember, true);

            //DateTimePicker
            BindingBuilderExtensions.RegisterDefaultBindingMember <DateTimePicker>(nameof(DateTimePicker.Value));
            memberProvider.Register(AttachedBindingMember.CreateMember <DateTimePicker, DateTime>(nameof(DateTimePicker.Value),
                                                                                                  (info, picker) => picker.Value,
                                                                                                  (info, picker, value) =>
            {
                if (value < picker.MinDate)
                {
                    picker.Value = picker.MinDate;
                }
                else if (value > picker.MaxDate)
                {
                    picker.Value = picker.MaxDate;
                }
                else
                {
                    picker.Value = value;
                }
            }, nameof(DateTimePicker.ValueChanged)));

            //ToolStripItem
            BindingBuilderExtensions.RegisterDefaultBindingMember <ToolStripButton>(nameof(ToolStripButton.Click));
            BindingBuilderExtensions.RegisterDefaultBindingMember <ToolStripMenuItem>(nameof(ToolStripMenuItem.Click));
            BindingBuilderExtensions.RegisterDefaultBindingMember <ToolStripItem>(nameof(ToolStripItem.Text));
            memberProvider.Register(AttachedBindingMember.CreateMember <ToolStripItem, object>(AttachedMemberConstants.ParentExplicit,
                                                                                               GetParentToolStripItem, null, ObserveParentMemberToolStripItem));
            memberProvider.Register(AttachedBindingMember.CreateMember <ToolStripItem, object>(AttachedMemberConstants.FindByNameMethod,
                                                                                               FindByNameMemberToolStripItem));

            //TabControl
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.Object.ItemsSource.Override <TabControl>());
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.TabControl.SelectedItem,
                                                                       GetSelectedItemTabControl, SetSelectedItemTabControl, nameof(TabControl.Selected)));

            //ComboBox
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.Object.ItemsSource.Override <ComboBox>());
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.Object.ItemsSource.Override <ComboBox>(),
                                                                       (info, box) => box.DataSource as IEnumerable,
                                                                       (info, box, value) => box.DataSource = value, nameof(ComboBox.DataSourceChanged)));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.ComboBox.SelectedItem,
                                                                       (info, box) => box.SelectedItem, (info, box, value) => box.SelectedItem = value, nameof(ComboBox.SelectedIndexChanged)));

            //DataGridView
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.Object.ItemsSource.Override <DataGridView>());
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.Object.ItemsSource.Override <DataGridView>(),
                                                                       (info, view) => view.DataSource as IEnumerable, (info, view, value) =>
            {
                view.DataSource = value;
                view.Refresh();
            }, nameof(DataGridView.DataSourceChanged)));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.DataGridView.SelectedItem,
                                                                       GetSelectedItemDataGridView, SetSelectedItemDataGridView, (info, view, arg3) =>
            {
                arg3 = arg3.ToWeakEventListener();
                EventHandler handler = null;
                handler = (sender, args) =>
                {
                    var gridView = (DataGridView)sender;
                    Action <DataGridView, IEventListener, EventHandler> action =
                        (dataGridView, listener, eventHandler) =>
                    {
                        if (!listener.TryHandle(dataGridView, EventArgs.Empty))
                        {
                            dataGridView.CurrentCellChanged -= eventHandler;
                        }
                    };
                    //To prevent this exception 'Operation not valid because it results in a reentrant call to the SetCurrentCellAddressCore function'
                    gridView.BeginInvoke(action, gridView, arg3, handler);
                };
                view.CurrentCellChanged += handler;
                return(WeakActionToken.Create(view, handler,
                                              (gridView, eventHandler) => gridView.CurrentCellChanged -= eventHandler));
            }));
        }