Ejemplo n.º 1
0
        private static List <View> GetViewAsObjects <TViewModel>(FragmentBase <TViewModel> bindingActivity) where TViewModel : IControllerBase
        {
            // Get the objects on the view
            var rootView = bindingActivity.Activity.Window.DecorView.FindViewById(Android.Resource.Id.Content);

            return(GetAllChildrenInView(rootView, true));
        }
Ejemplo n.º 2
0
        private static List <XElement> GetViewAsXmlElements <TViewModel>(FragmentBase <TViewModel> bindingActivity, int viewLayoutResourceId) where TViewModel : IControllerBase
        {
            List <XElement> xmlElements;

            using (var viewAsXmlReader = bindingActivity.Resources.GetLayout(viewLayoutResourceId))
            {
                using (var sb = new StringBuilder())
                {
                    while (viewAsXmlReader.Read())
                    {
                        sb.Append(viewAsXmlReader.ReadOuterXml());
                    }

                    var viewAsXDocument = XDocument.Parse(sb.ToString());
                    xmlElements = viewAsXDocument.Descendants().ToList();
                }
            }

            return(xmlElements);
        }
Ejemplo n.º 3
0
        public static IEnumerable <Binding> BindXml <TViewModel>(FragmentBase <TViewModel> bindingFragment, IControllerBase source) where TViewModel : IControllerBase
        {
            var bindings = new List <Binding>();

            List <View>     viewElements = null;
            List <XElement> xmlElements  = null;

            // Find the value of the ViewLayoutResourceId property
            var viewLayoutResourceIdProperty = bindingFragment.GetType().GetProperty(ViewLayoutResourceIdPropertyName);
            var viewLayoutResourceId         = (int)viewLayoutResourceIdProperty.GetValue(bindingFragment);

            if (viewLayoutResourceId > -1)
            {
                // Load the XML elements of the view
                xmlElements = GetViewAsXmlElements(bindingFragment, viewLayoutResourceId);
            }

            // If there is at least one 'Binding' attribute set in the XML file, get the view as objects
            if (xmlElements != null && xmlElements.Any(xe => xe.Attribute(BindingOperationXmlNamespace) != null))
            {
                viewElements = GetViewAsObjects(bindingFragment);
            }

            if (xmlElements != null && xmlElements.Any() && viewElements != null && viewElements.Any())
            {
                // Get all the binding operations inside the XML file.
                var bindingOperations = ExtractBindingOperationsFromLayoutFile(xmlElements, viewElements, source);
                if (bindingOperations != null && bindingOperations.Any())
                {
                    foreach (var bindingOperation in bindingOperations)
                    {
                        bindings.Add(BindInternal(bindingOperation, null));
                    }
                }
            }
            return(bindings);
        }