public void CreateMemberGenericGetterTest()
        {
            var          args     = new object[0];
            const string value    = "1";
            var          source   = new BindingSourceModel();
            const string path     = "path";
            Type         type     = typeof(string);
            var          property = AttachedBindingMember.CreateMember <BindingSourceModel, string>(path, (info, o, arg3) =>
            {
                info.ShouldNotBeNull();
                o.ShouldEqual(source);
                arg3.ShouldEqual(args);
                return(value);
            });

            property.Path.ShouldEqual(path);
            property.Type.ShouldEqual(type);
            property.CanRead.ShouldBeTrue();
            property.CanWrite.ShouldBeFalse();
            property.MemberType.ShouldEqual(BindingMemberType.Attached);

            property.GetValue(source, args).ShouldEqual(value);
            ShouldThrow(() => property.SetValue(source, new object[] { path }));
        }
        public void CreateMemberMemberAttachTest()
        {
            bool         isInvoked = false;
            var          source    = new BindingSourceModel();
            const string path      = "path";
            var          property  = AttachedBindingMember.CreateMember(path, typeof(string), (info, o) => null, (info, o, v) => { }, memberAttachedHandler:
                                                                        (model, args) =>
            {
                model.ShouldEqual(source);
                args.ShouldNotBeNull();
                isInvoked = true;
            });

            property.SetValue(source, new object[] { path });
            isInvoked.ShouldBeTrue();

            isInvoked = false;
            property.SetValue(source, new object[] { null });
            isInvoked.ShouldBeFalse();

            source = new BindingSourceModel();
            property.SetValue(source, new object[] { path });
            isInvoked.ShouldBeTrue();
        }
        public void CreateMemberSetterTest()
        {
            object       value    = null;
            var          source   = new BindingSourceModel();
            const string path     = "path";
            Type         type     = typeof(string);
            var          property = AttachedBindingMember.CreateMember(path, type, null, (info, o, v) =>
            {
                info.ShouldNotBeNull();
                o.ShouldEqual(source);
                v.ShouldEqual(path);
                value = v;
            });

            property.Path.ShouldEqual(path);
            property.Type.ShouldEqual(type);
            property.CanRead.ShouldBeFalse();
            property.CanWrite.ShouldBeTrue();
            property.MemberType.ShouldEqual(BindingMemberType.Attached);

            property.SetValue(source, new object[] { path });
            value.ShouldEqual(path);
            ShouldThrow(() => property.GetValue(source, null));
        }
Ejemplo n.º 4
0
 static VisualTreeManager()
 {
     RootMember = AttachedBindingMember.CreateMember <object, object>(AttachedMemberConstants.RootElement, GetRootElement, null, ObserveRootElement);
 }
Ejemplo n.º 5
0
        private static void RegisterActionBarMembers(IBindingMemberProvider memberProvider)
        {
            //PopupMenu
#if !APPCOMPAT
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.View.PopupMenuTemplate));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.View.PopupMenuPlacementTargetPath));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.View.PopupMenuPresenter));
#endif
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.View.PopupMenuEvent, PopupMenuEventChanged));

            //Menu
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(AttachedMembers.MenuItem.ActionView, (info, item) => item.GetActionView(), MenuItemUpdateActionView));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.MenuItem.ActionViewTemplateSelector, (o, args) => RefreshValue(o, AttachedMembers.MenuItem.ActionView)));
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(AttachedMembers.MenuItem.ActionProvider, (info, item) => item.GetActionProvider(), MenuItemUpdateActionProvider));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.MenuItem.ActionProviderTemplateSelector, (o, args) => RefreshValue(o, AttachedMembers.MenuItem.ActionProvider)));


            memberProvider.Register(AttachedBindingMember
                                    .CreateMember(AttachedMembers.MenuItem.IsActionViewExpanded, (info, item) => item.GetIsActionViewExpanded(),
                                                  SetIsActionViewExpanded, ObserveIsActionViewExpanded, (item, args) => item.SetOnActionExpandListener(new ActionViewExpandedListener(item))));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.MenuItem.ShowAsAction, null, (info, o, value) => o.SetShowAsActionFlags(value)));

            //ActionBar
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ActionBarTab.Content.Override <ActionBar.Tab>()));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ActionBar.ItemsSource.Override <ActionBar>(), (bar, args) => ActionBarUpdateItemsSource(bar)));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ActionBar.SelectedItem.Override <ActionBar>(), ActionBarSelectedItemChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ActionBar.ContextActionBarVisible.Override <ActionBar>(), ActionBarContextActionBarVisibleChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ActionBar.ContextActionBarTemplate.Override <ActionBar>()));
            memberProvider.Register(AttachedBindingMember.CreateMember <ActionBar, object>(AttachedMemberConstants.ParentExplicit, (info, bar) => bar.ThemedContext.GetActivity(), null));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.BackgroundDrawable.Override <ActionBar>(),
                                                        (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetBackgroundDrawable(
                        actionBar.ThemedContext.Resources.GetDrawable((int)args.NewValue));
                }
                else
                {
                    actionBar.SetBackgroundDrawable((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember(AttachedMembers.ActionBar.CustomView.Override <ActionBar>(),
                                                            (info, actionBar) => actionBar.CustomView,
                                                            (info, actionBar, value) =>
            {
                if (actionBar.CustomView != null)
                {
                    ParentObserver.GetOrAdd(actionBar.CustomView).Parent = null;
                }
                if (value is int)
                {
                    value = actionBar.ThemedContext.GetBindableLayoutInflater().Inflate((int)value, null);
                }
                actionBar.CustomView = (View)value;
                if (actionBar.CustomView != null)
                {
                    ParentObserver.GetOrAdd(actionBar.CustomView).Parent = actionBar;
                }
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.DisplayHomeAsUpEnabled.Override <ActionBar>(),
                                                        (actionBar, args) => actionBar.SetDisplayHomeAsUpEnabled(args.NewValue)));

            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember(AttachedMembers.ActionBar.DisplayOptions.Override <ActionBar>().Cast <ActionBarDisplayOptions>(),
                                                            (info, actionBar) => actionBar.GetActionBarDisplayOptions(),
                                                            (info, actionBar, value) =>
            {
                actionBar.SetActionBarDisplayOptions(value);
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.DisplayShowCustomEnabled.Override <ActionBar>(),
                                                        (actionBar, args) => actionBar.SetDisplayShowCustomEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.DisplayShowHomeEnabled.Override <ActionBar>(),
                                                        (actionBar, args) => actionBar.SetDisplayShowHomeEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.DisplayShowTitleEnabled.Override <ActionBar>(),
                                                        (actionBar, args) => actionBar.SetDisplayShowTitleEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.DisplayUseLogoEnabled.Override <ActionBar>(),
                                                        (actionBar, args) => actionBar.SetDisplayUseLogoEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.HomeButtonEnabled.Override <ActionBar>(),
                                                        (actionBar, args) => actionBar.SetHomeButtonEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.Icon.Override <ActionBar>(), (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetIcon((int)args.NewValue);
                }
                else
                {
                    actionBar.SetIcon((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.Logo.Override <ActionBar>(), (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetLogo((int)args.NewValue);
                }
                else
                {
                    actionBar.SetLogo((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember(AttachedMembers.ActionBar.NavigationMode.Override <ActionBar>().Cast <ActionBarNavigationMode>(),
                                                            (info, actionBar) => actionBar.GetNavigationMode(), ActionBarSetNavigationMode));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.SplitBackgroundDrawable.Override <ActionBar>(),
                                                        (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetSplitBackgroundDrawable(
                        actionBar.ThemedContext.Resources.GetDrawable((int)args.NewValue));
                }
                else
                {
                    actionBar.SetSplitBackgroundDrawable((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.ActionBar.StackedBackgroundDrawable.Override <ActionBar>(),
                                                        (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetStackedBackgroundDrawable(
                        actionBar.ThemedContext.Resources.GetDrawable((int)args.NewValue));
                }
                else
                {
                    actionBar.SetStackedBackgroundDrawable((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember(AttachedMembers.ActionBar.IsShowing.Override <ActionBar>(), (info, actionBar) => actionBar.IsShowing, SetActionBarIsShowing));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar, string>("Subtitle",
                                                                                (info, actionBar) => actionBar.Subtitle, (info, actionBar, value) =>
            {
                actionBar.Subtitle = value;
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar, string>("Title",
                                                                                (info, actionBar) => actionBar.Title, (info, actionBar, value) =>
            {
                actionBar.Title = value;
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember(AttachedMembers.ActionBar.Visible.Override <ActionBar>(), (info, actionBar) => actionBar.IsShowing, SetActionBarIsShowing));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ActionBar.DropDownItemTemplate.Override <ActionBar>()));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ActionBar.DropDownItemTemplateSelector.Override <ActionBar>()));

            //ActionBar.Tab
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ActionBarTab.ContentTemplateSelector.Override <ActionBar.Tab>()));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ActionBarTab.ContentTemplate.Override <ActionBar.Tab>()));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar.Tab, string>("ContentDescription",
                                                                                    (info, tab) => tab.ContentDescription,
                                                                                    (info, tab, value) =>
            {
                tab.SetContentDescription(value);
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember(AttachedMembers.ActionBarTab.CustomView.Override <ActionBar.Tab>(),
                                                            (info, tab) => tab.CustomView, (info, tab, value) =>
            {
                if (tab.CustomView != null)
                {
                    ParentObserver.GetOrAdd(tab.CustomView).Parent = null;
                }
                if (value is int)
                {
                    value = GetContextFromItem(tab).GetBindableLayoutInflater().Inflate((int)value, null);
                }
                tab.SetCustomView((View)value);
                if (tab.CustomView != null)
                {
                    ParentObserver.GetOrAdd(tab.CustomView).Parent = tab;
                }
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember(AttachedMembers.ActionBarTab.Icon.Override <ActionBar.Tab>(),
                                                            (info, tab) => tab.Icon, (info, tab, value) =>
            {
                if (value is int)
                {
                    tab.SetIcon((int)value);
                }
                else
                {
                    tab.SetIcon((Drawable)value);
                }
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar.Tab, string>("Text",
                                                                                    (info, tab) => tab.Text,
                                                                                    (info, tab, value) =>
            {
                tab.SetText(value);
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar.Tab, Object>("Tag",
                                                                                    (info, tab) => tab.Tag,
                                                                                    (info, tab, value) =>
            {
                tab.SetTag(value);
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember.CreateMember <ActionBar, HomeButtonImpl>("HomeButton",
                                                                                                   (info, bar) => HomeButtonImpl.GetOrAdd(bar), null));
            memberProvider.Register(AttachedBindingMember.CreateEvent <HomeButtonImpl>("Click",
                                                                                       (info, homeButton, arg3) => homeButton.AddWithUnsubscriber(arg3)));

            //SearchView
            BindingBuilderExtensions.RegisterDefaultBindingMember <SearchView>(() => v => v.Query);
            var queryMember = AttachedBindingMember.CreateMember <SearchView, string>("Query",
                                                                                      (info, searchView) => searchView.Query,
                                                                                      (info, searchView, value) => searchView.SetQuery(value, false), "QueryTextChange");
            memberProvider.Register(queryMember);
            memberProvider.Register("Text", queryMember);
        }
 public static void RegisterSwitchMembers()
 {
     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)));
 }
        private static void RegisterActionBarMembers(IBindingMemberProvider memberProvider)
        {
            memberProvider.Register(ActionBarTabContentMember);
            memberProvider.Register(ActionBarSelectedItemMember);
            memberProvider.Register(ActionBarItemsSourceMember);
            memberProvider.Register(ActionBarContextActionBarTemplateMember);
            memberProvider.Register(ActionBarContextActionBarVisibleMember);

            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <ActionBar, object>(AttachedMemberConstants.Parent, (info, bar) => bar.ThemedContext.GetActivity(), null));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, object>("BackgroundDrawable",
                                                                            (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetBackgroundDrawable(
                        actionBar.ThemedContext.Resources.GetDrawable((int)args.NewValue));
                }
                else
                {
                    actionBar.SetBackgroundDrawable((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar, object>("CustomView",
                                                                                (info, actionBar) => actionBar.CustomView,
                                                                                (info, actionBar, value) =>
            {
                if (actionBar.CustomView != null)
                {
                    ParentObserver.GetOrAdd(actionBar.CustomView).Parent = null;
                }
                if (value is int)
                {
                    actionBar.SetCustomView((int)value);
                }
                else
                {
                    actionBar.CustomView = (View)value;
                }
                if (actionBar.CustomView != null)
                {
                    ParentObserver.GetOrAdd(actionBar.CustomView).Parent = actionBar;
                }
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, bool>("DisplayHomeAsUpEnabled",
                                                                          (actionBar, args) => actionBar.SetDisplayHomeAsUpEnabled(args.NewValue)));

            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar, ActionBarDisplayOptions>("DisplayOptions",
                                                                                                 (info, actionBar) => actionBar.GetActionBarDisplayOptions(),
                                                                                                 (info, actionBar, value) =>
            {
                actionBar.SetActionBarDisplayOptions(value);
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, bool>("DisplayShowCustomEnabled",
                                                                          (actionBar, args) => actionBar.SetDisplayShowCustomEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, bool>("DisplayShowHomeEnabled",
                                                                          (actionBar, args) => actionBar.SetDisplayShowHomeEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, bool>("DisplayShowTitleEnabled",
                                                                          (actionBar, args) => actionBar.SetDisplayShowTitleEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, bool>("DisplayUseLogoEnabled",
                                                                          (actionBar, args) => actionBar.SetDisplayUseLogoEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, bool>("HomeButtonEnabled",
                                                                          (actionBar, args) => actionBar.SetHomeButtonEnabled(args.NewValue)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, object>("Icon", (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetIcon((int)args.NewValue);
                }
                else
                {
                    actionBar.SetIcon((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, object>("Logo", (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetLogo((int)args.NewValue);
                }
                else
                {
                    actionBar.SetLogo((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar, ActionBarNavigationMode>("NavigationMode",
                                                                                                 (info, actionBar) => actionBar.GetNavigationMode(), ActionBarSetNavigationMode));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, object>("SplitBackgroundDrawable",
                                                                            (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetSplitBackgroundDrawable(
                        actionBar.ThemedContext.Resources.GetDrawable((int)args.NewValue));
                }
                else
                {
                    actionBar.SetSplitBackgroundDrawable((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty <ActionBar, object>("StackedBackgroundDrawable",
                                                                            (actionBar, args) =>
            {
                if (args.NewValue is int)
                {
                    actionBar.SetStackedBackgroundDrawable(
                        actionBar.ThemedContext.Resources.GetDrawable((int)args.NewValue));
                }
                else
                {
                    actionBar.SetStackedBackgroundDrawable((Drawable)args.NewValue);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar, bool>("IsShowing", (info, actionBar) => actionBar.IsShowing, SetActionBarIsShowing));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar, string>("Subtitle",
                                                                                (info, actionBar) => actionBar.Subtitle, (info, actionBar, value) =>
            {
                actionBar.Subtitle = value;
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar, string>("Title",
                                                                                (info, actionBar) => actionBar.Title, (info, actionBar, value) =>
            {
                actionBar.Title = value;
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar, bool>("Visible", (info, actionBar) => actionBar.IsShowing, SetActionBarIsShowing));
            memberProvider.Register(AttachedBindingMember.CreateMember <ActionBar, View>("HomeButton", GetHomeButton, null));

            memberProvider.Register(
                AttachedBindingMember.CreateAutoProperty <ActionBar, int?>(AttachedMemberNames.DropDownItemTemplate));
            memberProvider.Register(
                AttachedBindingMember.CreateAutoProperty <ActionBar, IDataTemplateSelector>(
                    AttachedMemberNames.DropDownItemTemplateSelector));

            //ActionBar.Tab
            memberProvider.Register(
                AttachedBindingMember.CreateAutoProperty <ActionBar.Tab, IDataTemplateSelector>(
                    AttachedMemberConstants.ContentTemplateSelector));
            memberProvider.Register(
                AttachedBindingMember.CreateAutoProperty <ActionBar.Tab, int?>(
                    AttachedMemberConstants.ContentTemplate));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar.Tab, string>("ContentDescription",
                                                                                    (info, tab) => tab.ContentDescription,
                                                                                    (info, tab, value) =>
            {
                tab.SetContentDescription(value);
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar.Tab, object>("CustomView",
                                                                                    (info, tab) => tab.CustomView, (info, tab, value) =>
            {
                if (tab.CustomView != null)
                {
                    ParentObserver.GetOrAdd(tab.CustomView).Parent = null;
                }
                if (value is int)
                {
                    tab.SetCustomView((int)value);
                }
                else
                {
                    tab.SetCustomView((View)value);
                }
                if (tab.CustomView != null)
                {
                    ParentObserver.GetOrAdd(tab.CustomView).Parent = tab;
                }
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar.Tab, object>("Icon",
                                                                                    (info, tab) => tab.Icon, (info, tab, value) =>
            {
                if (value is int)
                {
                    tab.SetIcon((int)value);
                }
                else
                {
                    tab.SetIcon((Drawable)value);
                }
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar.Tab, string>("Text",
                                                                                    (info, tab) => tab.Text,
                                                                                    (info, tab, value) =>
            {
                tab.SetText(value);
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember <ActionBar.Tab, Object>("Tag",
                                                                                    (info, tab) => tab.Tag,
                                                                                    (info, tab, value) =>
            {
                tab.SetTag(value);
                return(true);
            }));

            //SearchView
            var queryMember = AttachedBindingMember.CreateMember <SearchView, string>("Query",
                                                                                      (info, searchView) => searchView.Query,
                                                                                      (info, searchView, value) => searchView.SetQuery(value, false), "QueryTextChange");

            memberProvider.Register(queryMember);
            memberProvider.Register("Text", queryMember);
        }
        private static void RegisterTableViewMembers(IBindingMemberProvider memberProvider)
        {
            BindingServiceProvider.ResourceResolver.AddType(typeof(UITableViewRowAnimation));
            BindingServiceProvider.ResourceResolver.AddType(typeof(UITableViewScrollPosition));
            BindingServiceProvider.ResourceResolver.AddType(typeof(UITableViewCellEditingStyle));
            BindingServiceProvider.ResourceResolver.AddType(typeof(UITableViewCellAccessory));
            BindingServiceProvider.ResourceResolver.AddType(typeof(UITableViewCellSelectionStyle));
            BindingServiceProvider.ResourceResolver.AddType(typeof(UITableViewCellSeparatorStyle));
            BindingServiceProvider.ResourceResolver.AddType(typeof(UITableViewCellStyle));

            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.UITableView.UseAnimations]    = BindingServiceProvider.TemplateMemberPriority + 1;
            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.UITableView.AddAnimation]     = BindingServiceProvider.TemplateMemberPriority + 1;
            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.UITableView.RemoveAnimation]  = BindingServiceProvider.TemplateMemberPriority + 1;
            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.UITableView.ReplaceAnimation] = BindingServiceProvider.TemplateMemberPriority + 1;
            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.UITableView.ScrollPosition]   = BindingServiceProvider.TemplateMemberPriority + 1;

            //UITableView
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIView.ItemsSource.Override <UITableView>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableView.ReadOnly));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableView.AddAnimation));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableView.RemoveAnimation));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableView.ReplaceAnimation));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableView.ScrollPosition));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableView.UseAnimations));
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UITableView.SelectedItemChangedEvent));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.ItemsSource.Override <UITableView>(), TableViewItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UITableView.SelectedItem,
                                                                       GetTableViewSelectedItem, SetTableViewSelectedItem, (info, view, arg3) => (IDisposable)view.SetBindingMemberValue(AttachedMembers.UITableView.SelectedItemChangedEvent, arg3)));
            var itemTemplateMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableView.ItemTemplateSelector, (view, args) => args.NewValue?.Initialize(view));

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

            //UITableViewCell
            BindingBuilderExtensions.RegisterDefaultBindingMember <UITableViewCell>(() => c => c.TextLabel.Text);
            var member = AttachedBindingMember.CreateEvent(AttachedMembers.UITableViewCell.AccessoryButtonTappedEvent);

            memberProvider.Register(member);
            memberProvider.Register("Click", member);
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UITableViewCell.DeleteClickEvent));
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UITableViewCell.InsertClickEvent));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableViewCell.Moveable));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableViewCell.TitleForDeleteConfirmation));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableViewCell.EditingStyle));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UITableViewCell.ShouldHighlight));
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UITableViewCell.ClickEvent));
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(
                                        AttachedMembers.UITableViewCell.Selected, (info, cell) =>
            {
                if (TableViewSourceBase.HasMask(cell, TableViewSourceBase.InitializingStateMask))
                {
                    return(null);
                }
                var cellBindable = cell as UITableViewCellBindable;
                if (cellBindable == null)
                {
                    return(cell.Selected);
                }
                return(cellBindable.SelectedBind.GetValueOrDefault());
            }, (info, cell, arg3) =>
            {
                var cellBindable = cell as UITableViewCellBindable;
                if (cellBindable == null)
                {
                    cell.Selected = arg3.GetValueOrDefault();
                }
                else
                {
                    cellBindable.SelectedBind = arg3;
                }
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(
                                        AttachedMembers.UITableViewCell.Highlighted, (info, cell) => cell.Highlighted,
                                        (info, cell, arg3) =>
            {
                if (cell.Highlighted == arg3)
                {
                    return(false);
                }
                cell.Highlighted = arg3;
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(
                                        AttachedMembers.UITableViewCell.Editing, (info, cell) => cell.Editing,
                                        (info, cell, arg3) =>
            {
                if (cell.Editing == arg3)
                {
                    return(false);
                }
                cell.Editing = arg3;
                return(true);
            }));
        }
Ejemplo n.º 9
0
 public static void RegisterTabControlMembers()
 {
     BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.Object.ItemsSource.Override <TabControl>());
     MemberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.TabControl.SelectedItem,
                                                                GetSelectedItemTabControl, SetSelectedItemTabControl, nameof(TabControl.Selected)));
 }
        private static void RegisterMenuMembers(IBindingMemberProvider memberProvider)
        {
            //IMenu
            memberProvider.Register(MenuItemsSourceMember);
            var menuEnabledMember = AttachedBindingMember.CreateAutoProperty <IMenu, bool?>(AttachedMemberConstants.Enabled, (menu, args) => menu.SetGroupEnabled(0, args.NewValue.GetValueOrDefault()));

            memberProvider.Register(menuEnabledMember);
            memberProvider.Register("IsEnabled", menuEnabledMember);

            var menuVisibleMember = AttachedBindingMember.CreateAutoProperty <IMenu, bool?>("Visible",
                                                                                            (menu, args) => menu.SetGroupVisible(0, args.NewValue.GetValueOrDefault()));

            memberProvider.Register(menuVisibleMember);
            memberProvider.Register("IsVisible", menuVisibleMember);

            //IMenuItem
#if !API8
            memberProvider.Register(MenuItemActionViewMember);
            memberProvider.Register(MenuItemActionViewSelectorMember);

            memberProvider.Register(MenuItemActionProviderMember);
            memberProvider.Register(MenuItemActionProviderSelectorMember);
#endif
            memberProvider.Register(IsCheckedMenuItemMember);
            memberProvider.Register(AttachedBindingMember.CreateEvent <IMenuItem>("Click", SetClickEventValue));

            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, object>("AlphabeticShortcut",
                                                                      (info, item) => item.AlphabeticShortcut,
                                                                      (info, item, value) =>
            {
                if (value is char)
                {
                    item.SetAlphabeticShortcut((char)value);
                }
                else
                {
                    item.SetAlphabeticShortcut(value.ToStringSafe()[0]);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, object>("Icon", (info, item) => item.Icon,
                                                                      (info, item, value) =>
            {
                if (value is int)
                {
                    item.SetIcon((int)value);
                }
                else
                {
                    item.SetIcon((Drawable)value);
                }
            }));

            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, bool>("IsCheckable",
                                                                    (info, item) => item.IsCheckable,
                                                                    (info, item, value) => item.SetCheckable(value)));

            var menuItemEnabled = AttachedBindingMember.CreateMember <IMenuItem, bool>(AttachedMemberConstants.Enabled,
                                                                                       (info, item) => item.IsEnabled,
                                                                                       (info, item, value) => item.SetEnabled(value));
            memberProvider.Register(menuItemEnabled);
            memberProvider.Register("IsEnabled", menuItemEnabled);
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, bool>("IsVisible", (info, item) => item.IsVisible,
                                                                    (info, item, value) => item.SetVisible(value)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, object>("NumericShortcut",
                                                                      (info, item) => item.NumericShortcut,
                                                                      (info, item, value) =>
            {
                if (value is char)
                {
                    item.SetNumericShortcut((char)value);
                }
                else
                {
                    item.SetNumericShortcut(value.ToStringSafe()[0]);
                }
            }));
            memberProvider.Register(AttachedBindingMember.CreateMember <IMenuItem, string>("Title",
                                                                                           (info, item) => item.TitleFormatted.ToString(),
                                                                                           (info, item, value) => item.SetTitle(value)));
            memberProvider.Register(AttachedBindingMember.CreateMember <IMenuItem, string>("TitleCondensed",
                                                                                           (info, item) => item.TitleCondensedFormatted.ToString(),
                                                                                           (info, item, value) => item.SetTitleCondensed(value)));

#if !API8
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, bool>("IsActionViewExpanded", (info, item) => item.GetIsActionViewExpanded(), SetIsActionViewExpanded,
                                                                    ObserveIsActionViewExpanded, (item, args) =>
            {
#if API8SUPPORT
                item.SetOnActionExpandListener(new ActionViewExpandedListener(item));
#else
                item.SetOnActionExpandListener(ActionViewExpandedListener.Instance);
#endif
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, ShowAsAction>("ShowAsAction", null, (info, o, value) => o.SetShowAsActionFlags(value)));
#endif
        }
Ejemplo n.º 11
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");

            //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"));
        }
Ejemplo n.º 13
0
        private static void Register(IBindingMemberProvider memberProvider)
        {
            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.Object.StableIdProvider] = BindingServiceProvider.TemplateMemberPriority - 1;
            RegisterMenuMembers(memberProvider);
            RegisterViewMembers(memberProvider);
            RegisterPreferenceMembers(memberProvider);
            BindingBuilderExtensions.RegisterDefaultBindingMember <Button>(nameof(Button.Click));
            BindingBuilderExtensions.RegisterDefaultBindingMember <TextView>(nameof(TextView.Text));
            BindingBuilderExtensions.RegisterDefaultBindingMember <CheckBox>(nameof(CheckBox.Checked));
            BindingBuilderExtensions.RegisterDefaultBindingMember <CompoundButton>(nameof(CompoundButton.Checked));
            BindingBuilderExtensions.RegisterDefaultBindingMember <SeekBar>(nameof(SeekBar.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);
                }
                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>(nameof(Activity.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>(nameof(RatingBar.Rating));
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <RatingBar, float>(nameof(RatingBar.Rating), (info, btn) => btn.Rating,
                                                                     (info, btn, value) => btn.Rating = value, nameof(RatingBar.RatingBarChange)));

            //AdapterView
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.AdapterView.DropDownItemTemplate, ViewGroupTemplateChanged));
            memberProvider.Register(AttachedBindingMember
                                    .CreateAutoProperty(AttachedMembers.AdapterView.DropDownItemTemplateSelector, ViewGroupTemplateChanged));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.AdapterView.SelectedItem, AdapterViewSelectedItemChanged,
                                                                             AdapterViewSelectedItemMemberAttached));
            var selectedItemPosMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.AdapterView.SelectedItemPosition,
                                                                                 AdapterViewSelectedItemPositionChanged, AdapterViewSelectedItemPositionMemberAttached, (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, (view, args) =>
            {
                view.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)));

            //TextView
            if (TextViewSetTextMethodId != IntPtr.Zero)
            {
                var fastTextMember = AttachedBindingMember.CreateMember <TextView, string>("TextEx", (info, view) => view.Text, (info, view, arg3) =>
                {
                    //Default Xamarin implementation creates and release new Java.Lang.String on every text change, can be replaced with direct method call
                    //                    Java.Lang.String @string = value != null ? new Java.Lang.String(value) : (Java.Lang.String)null;
                    //                    this.TextFormatted = (ICharSequence)@string;
                    //                    if (@string == null)
                    //                        return;
                    //                    @string.Dispose();

                    if (arg3 == null)
                    {
                        JNIEnv.CallVoidMethod(view.Handle, TextViewSetTextMethodId, NullJValue);
                    }
                    else if (arg3 == "")
                    {
                        JNIEnv.CallVoidMethod(view.Handle, TextViewSetTextMethodId, EmptyStringJValue);
                    }
                    else
                    {
                        var stringPtr = JNIEnv.NewString(arg3);
                        try
                        {
                            unsafe
                            {
                                JValue *ptr = stackalloc JValue[1];
                                *ptr        = new JValue(stringPtr);
                                JNIEnv.CallVoidMethod(view.Handle, TextViewSetTextMethodId, ptr);
                            }
                        }
                        finally
                        {
                            JNIEnv.DeleteLocalRef(stringPtr);
                        }
                    }
                }, nameof(TextView.TextChanged));
                memberProvider.Register(fastTextMember);
                if (PlatformExtensions.EnableFastTextViewTextProperty)
                {
                    memberProvider.Register(nameof(TextView.Text), fastTextMember);
                }
            }

            //AutoCompleteTextView
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.AutoCompleteTextView.FilterText));
            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, nameof(TimePicker.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([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));
            }
        }
 public static void RegisterDefaultBindingMember <TType>([NotNull] string member)
     where TType : class
 {
     Should.NotBeNull(member, "member");
     BindingServiceProvider.MemberProvider.Register(AttachedBindingMember.CreateMember(DefautBindingMemberDescriptor.Override <TType>(), (info, type) => member, null));
 }
        private static void RegisterMenuMembers(IBindingMemberProvider memberProvider)
        {
            //IMenu
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.Menu.ItemsSource, MenuItemsSourceChanged));
            var menuEnabledMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.Menu.Enabled,
                                                                             (menu, args) => menu.SetGroupEnabled(0, args.NewValue.GetValueOrDefault()));

            memberProvider.Register(menuEnabledMember);
            memberProvider.Register("IsEnabled", menuEnabledMember);

            var menuVisibleMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.Menu.Visible,
                                                                             (menu, args) => menu.SetGroupVisible(0, args.NewValue.GetValueOrDefault()));

            memberProvider.Register(menuVisibleMember);
            memberProvider.Register("IsVisible", menuVisibleMember);

            //IMenuItem
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.MenuItem.Click);
            memberProvider.Register(AttachedBindingMember.CreateNotifiableMember(AttachedMembers.MenuItem.IsChecked,
                                                                                 (info, item) => item.IsChecked, (info, item, value) =>
            {
                if (value == item.IsChecked)
                {
                    return(false);
                }
                item.SetChecked(value);
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.MenuItem.Click, SetClickEventValue,
                                                                      (item, args) => item.SetOnMenuItemClickListener(new MenuItemOnMenuItemClickListener(item))));

            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, object>("AlphabeticShortcut",
                                                                      (info, item) => item.AlphabeticShortcut,
                                                                      (info, item, value) =>
            {
                if (value is char)
                {
                    item.SetAlphabeticShortcut((char)value);
                }
                else
                {
                    item.SetAlphabeticShortcut(value.ToStringSafe()[0]);
                }
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember(AttachedMembers.MenuItem.Icon, (info, item) => item.Icon,
                                                  (info, item, value) =>
            {
                if (value is int)
                {
                    item.SetIcon((int)value);
                }
                else
                {
                    item.SetIcon((Drawable)value);
                }
            }));

            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, bool>("IsCheckable",
                                                                    (info, item) => item.IsCheckable,
                                                                    (info, item, value) => item.SetCheckable(value)));

            var menuItemEnabled = AttachedBindingMember.CreateMember <IMenuItem, bool>(AttachedMemberConstants.Enabled,
                                                                                       (info, item) => item.IsEnabled,
                                                                                       (info, item, value) => item.SetEnabled(value));

            memberProvider.Register(menuItemEnabled);
            memberProvider.Register("IsEnabled", menuItemEnabled);
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, bool>("IsVisible", (info, item) => item.IsVisible,
                                                                    (info, item, value) => item.SetVisible(value)));
            memberProvider.Register(AttachedBindingMember
                                    .CreateMember <IMenuItem, object>("NumericShortcut",
                                                                      (info, item) => item.NumericShortcut,
                                                                      (info, item, value) =>
            {
                if (value is char)
                {
                    item.SetNumericShortcut((char)value);
                }
                else
                {
                    item.SetNumericShortcut(value.ToStringSafe()[0]);
                }
            }));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.MenuItem.Title,
                                                                       (info, item) => item.TitleFormatted.ToStringSafe(),
                                                                       (info, item, value) => item.SetTitle(value)));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.MenuItem.TitleCondensed,
                                                                       (info, item) => item.TitleCondensedFormatted.ToStringSafe(),
                                                                       (info, item, value) => item.SetTitleCondensed(value)));
        }
Ejemplo n.º 17
0
 public static void RegisterMenuItemActionViewMembers()
 {
     MemberProvider.Register(AttachedBindingMember.CreateNotifiableMember(AttachedMembers.MenuItem.ActionView, (info, item) => item.GetActionView(), MenuItemUpdateActionView));
     MemberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.MenuItem.ActionViewTemplateSelector, (o, args) => RefreshValue(o, AttachedMembers.MenuItem.ActionView)));
     MemberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.MenuItem.IsActionViewExpanded, (info, item) => item.GetIsActionViewExpanded(), SetIsActionViewExpanded, ObserveIsActionViewExpanded, (item, args) => item.SetOnActionExpandListener(new ActionViewExpandedListener(item))));
 }
 public static void RegisterElementMembers()
 {
     MemberProvider.Register(AttachedBindingMember
                             .CreateMember <Element, object>(AttachedMemberConstants.Parent, GetParentValue, SetParentValue, ObserveParentMember));
     MemberProvider.Register(typeof(Element), nameof(Element.BindingContext), BindingMemberProvider.BindingContextMember, true);
 }
Ejemplo n.º 19
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));
            }));
        }
Ejemplo n.º 20
0
 public static void RegisterWebBrowserMembers()
 {
     MemberProvider.Register(AttachedBindingMember.CreateMember <WebBrowser, Uri>(nameof(WebBrowser),
                                                                                  (info, browser) => browser.Source, (info, browser, arg3) => browser.Source = arg3, nameof(WebBrowser.Navigated)));
 }
        private static void RegisterCollectionViewMembers(IBindingMemberProvider memberProvider)
        {
            BindingServiceProvider.ResourceResolver.AddType(typeof(UICollectionViewScrollPosition));
            BindingServiceProvider.ResourceResolver.AddType(typeof(UICollectionViewScrollDirection));

            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.UICollectionView.UseAnimations]  = BindingServiceProvider.TemplateMemberPriority + 1;
            BindingServiceProvider.BindingMemberPriorities[AttachedMembers.UICollectionView.ScrollPosition] = BindingServiceProvider.TemplateMemberPriority + 1;

            //UICollectionView
            BindingBuilderExtensions.RegisterDefaultBindingMember(AttachedMembers.UIView.ItemsSource.Override <UICollectionView>());
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UICollectionView.UseAnimations));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UICollectionView.ScrollPosition));
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UICollectionView.SelectedItemChangedEvent));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UIView.ItemsSource.Override <UICollectionView>(), CollectionViewItemsSourceChanged));
            memberProvider.Register(AttachedBindingMember.CreateMember(AttachedMembers.UICollectionView.SelectedItem,
                                                                       GetCollectionViewSelectedItem, SetCollectionViewSelectedItem, (info, view, arg3) => (IDisposable)view.SetBindingMemberValue(AttachedMembers.UICollectionView.SelectedItemChangedEvent, arg3)));
            var itemTemplateMember = AttachedBindingMember.CreateAutoProperty(AttachedMembers.UICollectionView.ItemTemplateSelector, (view, args) => args.NewValue?.Initialize(view));

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

            //UICollectionViewCell
            memberProvider.Register(AttachedBindingMember.CreateEvent(AttachedMembers.UICollectionViewCell.ClickEvent));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember(AttachedMembers.UICollectionViewCell.Selected, (info, cell) =>
            {
                if (CollectionViewSourceBase.HasMask(cell, CollectionViewSourceBase.InitializingStateMask))
                {
                    return(null);
                }
                var cellBindable = cell as UICollectionViewCellBindable;
                if (cellBindable == null)
                {
                    return(cell.Selected);
                }
                return(cellBindable.SelectedBind.GetValueOrDefault());
            },
                                                            (info, cell, arg3) =>
            {
                var cellBindable = cell as UICollectionViewCellBindable;
                if (cellBindable == null)
                {
                    cell.Selected = arg3.GetValueOrDefault();
                }
                else
                {
                    cellBindable.SelectedBind = arg3;
                }
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember
                                    .CreateNotifiableMember(AttachedMembers.UICollectionViewCell.Highlighted, (info, cell) => cell.Highlighted,
                                                            (info, cell, arg3) =>
            {
                cell.Highlighted = arg3;
                return(true);
            }));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UICollectionViewCell.ShouldHighlight));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UICollectionViewCell.ShouldDeselect));
            memberProvider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.UICollectionViewCell.ShouldSelect));
        }
        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));
            }));
        }
 public static void RegisterDatePickerMembers()
 {
     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)));
 }
Ejemplo n.º 24
0
        protected override bool LoadInternal()
        {
            IBindingMemberProvider provider = BindingServiceProvider.MemberProvider;

            //NavigationView
            provider.Register(
                AttachedBindingMember.CreateAutoProperty(AttachedMembersDesign.NavigationView.MenuTemplate,
                                                         NavigationViewMenuTemplateChanged));

            //TabLayout
            provider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembers.ViewGroup.ItemsSource.Override <TabLayout>(), TabLayoutItemsSourceChanged));
            provider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembersDesign.TabLayout.RestoreSelectedIndex));
            provider.Register(AttachedBindingMember.CreateMember(AttachedMembersDesign.TabLayout.SelectedItem,
                                                                 TabLayoutGetSelectedItem, TabLayoutSetSelectedItem, (info, layout, arg3) =>
            {
                arg3 = arg3.ToWeakEventListener();
                layout.TabSelected   += arg3.Handle;
                layout.TabUnselected += arg3.Handle;
                return(WeakActionToken.Create(layout, arg3, (tabLayout, listener) =>
                {
                    tabLayout.TabSelected -= listener.Handle;
                    tabLayout.TabUnselected -= listener.Handle;
                }));
            }));

            //TabLayout.Tab
            provider.Register(AttachedBindingMember.CreateNotifiableMember <TabLayout.Tab, string>("Text",
                                                                                                   (info, tab) => tab.Text,
                                                                                                   (info, tab, arg3) =>
            {
                tab.SetText(arg3);
                return(true);
            }));
            provider.Register(AttachedBindingMember.CreateNotifiableMember <TabLayout.Tab, string>("ContentDescription",
                                                                                                   (info, tab) => tab.ContentDescription,
                                                                                                   (info, tab, arg3) =>
            {
                tab.SetContentDescription(arg3);
                return(true);
            }));
            provider.Register(AttachedBindingMember.CreateNotifiableMember <TabLayout.Tab, object>("Icon",
                                                                                                   (info, tab) => tab.Icon,
                                                                                                   (info, tab, arg3) =>
            {
                if (arg3 is int)
                {
                    tab.SetIcon((int)arg3);
                }
                else
                {
                    tab.SetIcon((Drawable)arg3);
                }
                return(true);
            }));
            provider.Register(AttachedBindingMember.CreateNotifiableMember <TabLayout.Tab, Object>("Tag",
                                                                                                   (info, tab) => tab.Tag,
                                                                                                   (info, tab, arg3) =>
            {
                tab.SetTag(arg3);
                return(true);
            }));

            //EditText
            provider.Register(AttachedBindingMember.CreateAutoProperty <EditText, string>(BindingErrorProvider.ErrorPropertyName,
                                                                                          (text, args) =>
            {
                var layout = text.Parent as TextInputLayout;
                if (layout == null)
                {
                    text.Error = args.NewValue;
                }
                else
                {
                    text.Error   = null;
                    layout.Error = args.NewValue;
                }
            }, getDefaultValue: (text, info) => text.Error));

            //Activity
            provider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembersDesign.Activity.SnackbarView));
            provider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembersDesign.Activity.SnackbarViewSelector));
            provider.Register(AttachedBindingMember.CreateAutoProperty(AttachedMembersDesign.Activity.SnackbarTemplateSelector));

            if (IocContainer != null)
            {
                IToastPresenter toastPresenter;
                IocContainer.TryGet(out toastPresenter);
                IocContainer.BindToConstant <IToastPresenter>(new SnackbarToastPresenter(IocContainer.Get <IThreadManager>(), toastPresenter));
            }

            return(true);
        }
        public static void RegisterDialogElementMembers()
        {
            DefaultCollectionViewManager.InsertInternalHandler = (view, index, item) =>
            {
                var section = view as Section;
                if (section != null)
                {
                    section.Insert(index, (Element)item);
                    ((Element)item).RaiseParentChanged();
                    return(true);
                }

                var rootElement = view as RootElement;
                if (rootElement != null)
                {
                    rootElement.Insert(index, (Section)item);
                    ((Section)item).RaiseParentChanged();
                    return(true);
                }
                return(false);
            };
            DefaultCollectionViewManager.RemoveAtInternalHandler = (view, index) =>
            {
                var section = view as Section;
                if (section != null)
                {
                    var element = section[index];
                    section.Remove(index);
                    element.ClearBindingsRecursively(true, true);
                    element.DisposeEx();
                    return(true);
                }

                var rootElement = view as RootElement;
                if (rootElement != null)
                {
                    var element = rootElement[index];
                    rootElement.RemoveAt(index);
                    element.ClearBindingsRecursively(true, true);
                    element.DisposeEx();
                    return(true);
                }
                return(false);
            };
            DefaultCollectionViewManager.ClearInternalHandler = view =>
            {
                var section = view as Section;
                if (section != null)
                {
                    var elements = section.OfType <Element>().ToArray();
                    section.Clear();
                    foreach (var element in elements)
                    {
                        element.ClearBindingsRecursively(true, true);
                        element.DisposeEx();
                    }
                    return(true);
                }

                var rootElement = view as RootElement;
                if (rootElement != null)
                {
                    var elements = rootElement.ToArray();
                    rootElement.Clear();
                    foreach (var element in elements)
                    {
                        element.ClearBindingsRecursively(true, true);
                        element.DisposeEx();
                    }
                    return(true);
                }
                return(false);
            };

            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));
        }
        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));
            }));
        }