Example #1
0
        private static void BusyMessageChanged(View view, AttachedMemberChangedEventArgs <string> args)
        {
            var dialog = ProgressDialogAttachedProperty.GetValue(view, null);

            if (dialog == null)
            {
                dialog = new ProgressDialog(view.Context);
                ProgressDialogAttachedProperty.SetValue(view, dialog);
            }
            dialog.SetMessage(args.NewValue);
        }
Example #2
0
        private static void IsBusyChanged(UIView uiView, AttachedMemberChangedEventArgs <bool> args)
        {
            //Ignoring view and set overlay over main window
            uiView = UIApplication.SharedApplication.Windows[0];
            LoadingOverlay busyIndicator = BusyViewMember.GetValue(uiView, null);

            if (args.NewValue)
            {
                busyIndicator.Show(uiView);
            }
            else
            {
                busyIndicator.Hide();
            }
        }
        public void AutoPropertyTest()
        {
            var          source = new BindingSourceModel();
            const string path   = "path";
            Type         type   = typeof(string);
            IAttachedBindingMemberInfo <object, object> property = AttachedBindingMember.CreateAutoProperty(path, type);

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

            property.GetValue(source, null).ShouldBeNull();
            property.SetValue(source, new object[] { path });
            property.GetValue(source, null).ShouldEqual(path);
        }
        private static bool MenuItemUpdateActionView(IBindingMemberInfo bindingMemberInfo, IMenuItem menuItem, object content)
        {
            var actionView = menuItem.GetActionView();

            if (actionView != null)
            {
                ParentObserver.GetOrAdd(actionView).Parent = null;
            }

            var selector = MenuItemActionViewSelectorMember.GetValue(menuItem, null);

            if (selector != null)
            {
                object template = selector.SelectTemplate(content, menuItem);
                if (template != null)
                {
                    content = template;
                }
            }
            if (content == null)
            {
                menuItem.SetActionView(null);
                return(true);
            }

            int viewId;

            if (int.TryParse(content.ToString(), out viewId))
            {
                menuItem.SetActionView(viewId);
                actionView = menuItem.GetActionView();
            }
            else
            {
                actionView = content as View;
                if (actionView == null)
                {
                    Type viewType = TypeCache <View> .Instance.GetTypeByName(content.ToString(), false, true);

                    actionView = viewType.CreateView(GetContextFromMenuItem(menuItem));
                }
                menuItem.SetActionView(actionView);
            }
            ParentObserver.GetOrAdd(actionView).Parent = menuItem;
            var bindings = MenuItemTemplate.GetActionViewBind(menuItem);

            if (!string.IsNullOrEmpty(bindings))
            {
                BindingServiceProvider.BindingProvider.CreateBindingsFromString(actionView, bindings, null);
            }
            return(true);
        }
        private static void ActionBarUpdateItemsSource(ActionBar actionBar)
        {
            switch (actionBar.GetNavigationMode())
            {
            case ActionBarNavigationMode.List:
                IItemsSourceAdapter sourceAdapter = ItemsSourceAdapter.Get(actionBar);
                if (sourceAdapter == null)
                {
                    sourceAdapter = ItemsSourceAdapter.Factory(actionBar, actionBar.ThemedContext, DataContext.Empty);
                    ItemsSourceAdapter.Set(actionBar, sourceAdapter);
                    actionBar.SetListNavigationCallbacks(sourceAdapter, new ActionBarNavigationListener(actionBar));
                }
                sourceAdapter.ItemsSource = ActionBarItemsSourceMember.GetValue(actionBar, null);
                break;

            case ActionBarNavigationMode.Standard:
                ActionBarSelectedItemMember.SetValue(actionBar, BindingExtensions.NullValue);
                actionBar.SetListNavigationCallbacks(null, null);
                var generator = ItemsSourceGeneratorBase.Get(actionBar);
                if (generator != null)
                {
                    generator.SetItemsSource(null);
                }
                var adapter = ItemsSourceAdapter.Get(actionBar);
                if (adapter != null)
                {
                    adapter.ItemsSource = null;
                }
                break;

            case ActionBarNavigationMode.Tabs:
                var tabGenerator = ItemsSourceGeneratorBase.Get(actionBar);
                if (tabGenerator != null)
                {
                    tabGenerator.SetItemsSource(ActionBarItemsSourceMember.GetValue(actionBar, null));
                }
                break;
            }
        }
Example #6
0
        private static void IsBusyChanged(Control control, AttachedMemberChangedEventArgs <bool> args)
        {
            BusyIndicator busyIndicator = BusyViewMember.GetValue(control, null);

            if (args.NewValue)
            {
                for (int index = 0; index < control.Controls.Count; index++)
                {
                    control.Controls[index].Enabled = false;
                }
                control.Controls.Add(busyIndicator);
                busyIndicator.Left = (control.ClientSize.Width - busyIndicator.Width) / 2;
                busyIndicator.Top  = (control.ClientSize.Height - busyIndicator.Height) / 2;
                busyIndicator.BringToFront();
            }
            else
            {
                control.Controls.Remove(busyIndicator);
                for (int index = 0; index < control.Controls.Count; index++)
                {
                    control.Controls[index].Enabled = true;
                }
            }
        }
Example #7
0
        private static void UpdateContent(ViewGroup sender, object newContent, object[] args)
        {
            if (newContent == null && args == RemoveViewValue)
            {
                return;
            }

            //NOTE cheking if it's a view group listener.
            if (args != null && args.Length == 2 && args[1] == AddViewValue)
            {
                return;
            }
            var templateId       = ContentTemplateIdMember.GetValue(sender, null);
            var templateSelector = ContentTemplateSelectorMember.GetValue(sender, null);

            sender.SetContentView(newContent, templateId, templateSelector);
        }
Example #8
0
        private static void AdapterViewSelectedItemPositionChanged(AdapterView sender,
                                                                   AttachedMemberChangedEventArgs <int> args)
        {
            if (!(sender is ListView) || ScrollToSelectedItemMember.GetValue(sender, null))
            {
                sender.SetSelection(args.NewValue);
            }

            var adapter = GetAdapter(sender) as ItemsSourceAdapter;

            if (adapter == null)
            {
                return;
            }
            object item = adapter.GetRawItem(args.NewValue);

            AdapterViewSelectedItemMember.SetValue(sender, item);
        }
        private static void UpdateContent(Control container, object value, IDataTemplateSelector selector)
        {
            if (selector != null)
            {
                value = selector.SelectTemplateWithContext(value, container);
            }
            var content = value as Control;

            if (content == null)
            {
                var viewModel = value as IViewModel;
                if (viewModel != null)
                {
                    content = ViewModelToViewConverter.Instance.Convert(viewModel) as Control;
                }
            }
            if (content == null && value != null)
            {
                Tracer.Warn("The content value {0} is not a Control.", value);
                content = new TextBox
                {
                    ReadOnly  = true,
                    Text      = value.ToString(),
                    Multiline = true
                };
            }
            IContentViewManager viewManager = ContentViewManagerMember.GetValue(container, null);

            if (viewManager == null)
            {
                container.Controls.Clear();
                if (content != null)
                {
                    content.Dock     = DockStyle.Fill;
                    content.AutoSize = true;
                    container.Size   = content.Size;
                    container.Controls.Add(content);
                }
            }
            else
            {
                viewManager.SetContent(container, content);
            }
        }
        private static bool MenuItemUpdateActionProvider(IBindingMemberInfo bindingMemberInfo, IMenuItem menuItem, object content)
        {
            var selector = MenuItemActionProviderSelectorMember.GetValue(menuItem, null);

            if (selector != null)
            {
                object template = selector.SelectTemplate(content, menuItem);
                if (template != null)
                {
                    content = template;
                }
            }
            if (content == null)
            {
                menuItem.SetActionProvider(null);
                return(true);
            }

            var actionProvider = content as ActionProvider;

            if (actionProvider == null)
            {
                Type viewType = TypeCache <ActionProvider> .Instance.GetTypeByName(content.ToString(), false, true);

                actionProvider = (ActionProvider)Activator.CreateInstance(viewType, GetContextFromMenuItem(menuItem));
            }
            //TODO WRAPPER???
            menuItem.SetActionProvider(actionProvider);
            BindingExtensions.AttachedParentMember.SetValue(actionProvider, menuItem);
            var bindings = MenuItemTemplate.GetActionProviderBind(menuItem);

            if (!string.IsNullOrEmpty(bindings))
            {
                BindingServiceProvider.BindingProvider.CreateBindingsFromString(actionProvider, bindings, null);
            }
            return(true);
        }
Example #11
0
 private static void ContentTemplateSelectorChanged(ViewGroup sender,
                                                    AttachedMemberChangedEventArgs <IDataTemplateSelector> args)
 {
     UpdateContent(sender, ContentMember.GetValue(sender, null), args.Args);
 }
 private static void ContentChanged(Control control, AttachedMemberChangedEventArgs <object> args)
 {
     UpdateContent(control, args.NewValue, ContentTemplateMember.GetValue(control, null));
 }
 private static void ContentTemplateChanged(Control control, AttachedMemberChangedEventArgs <IDataTemplateSelector> args)
 {
     UpdateContent(control, ContentMember.GetValue(control, null), args.NewValue);
 }
        private static void UpdateContent(UIView container, object value, IDataTemplateSelector selector)
        {
            var viewController = ServiceProvider
                                 .AttachedValueProvider
                                 .GetValue <UIViewController>(container, ContentControllerPath, false);

            if (viewController != null)
            {
                viewController.RemoveFromParentViewController();
                ServiceProvider.AttachedValueProvider.Clear(container, ContentControllerPath);
                viewController.InititalizeRestorationIdentifier();
            }

            if (selector != null)
            {
                value = selector.SelectTemplateWithContext(value, container);
            }
            var viewModel = value as IViewModel;

            if (viewModel != null)
            {
                value = ViewModelToViewConverter.Instance.Convert(viewModel);
            }

            var view = value as UIView;

            if (view == null)
            {
                viewController = value as UIViewController;
                if (viewController == null)
                {
                    if (value != null)
                    {
                        view = new UITextView(new RectangleF(4, 4, 300, 30))
                        {
                            Editable          = false,
                            DataDetectorTypes = UIDataDetectorType.None,
                            Text = value.ToString()
                        }
                    }
                    ;
                }
                else
                {
                    var currentController = container.FindParent <UIViewController>();
                    if (currentController != null)
                    {
                        ServiceProvider.AttachedValueProvider.SetValue(container, ContentControllerPath, viewController);
                        viewController.WillMoveToParentViewController(currentController);
                        currentController.AddChildViewController(viewController);
                        viewController.DidMoveToParentViewController(currentController);
                        viewController.RestorationIdentifier = string.Empty;
                        view = viewController.View;
                    }
                }
            }

            IContentViewManager viewManager = ContentViewManagerMember.GetValue(container, null);

            if (viewManager == null)
            {
                container.ClearSubViews();
                if (view != null)
                {
                    view.Frame            = container.Frame;
                    view.AutoresizingMask = UIViewAutoresizing.All;
                    container.AddSubviewEx(view);
                }
            }
            else
            {
                viewManager.SetContent(container, view);
            }
        }