Ejemplo n.º 1
0
 /// <include file="../../docs/Microsoft.Maui.Controls/TableSectionBase.xml" path="//Member[@MemberName='Add']/Docs" />
 public void Add(T item)
 {
     _children.Add(item);
     if (item is IVisualTreeElement element)
     {
         VisualDiagnostics.OnChildAdded(this, element);
     }
 }
Ejemplo n.º 2
0
        /// <include file="../../docs/Microsoft.Maui.Controls/TableSectionBase.xml" path="//Member[@MemberName='Insert']/Docs" />
        public void Insert(int index, T item)
        {
            if (item is IVisualTreeElement element)
            {
                VisualDiagnostics.OnChildAdded(this, element, index);
            }

            _children.Insert(index, item);
        }
Ejemplo n.º 3
0
        public static object Create(string xaml, bool doNotThrow, bool useDesignProperties)
        {
            doNotThrow = doNotThrow || ResourceLoader.ExceptionHandler2 != null;
            void ehandler(Exception e) => ResourceLoader.ExceptionHandler2?.Invoke((e, null));

            object inflatedView = null;

            using (var textreader = new StringReader(xaml))
                using (var reader = XmlReader.Create(textreader))
                {
                    while (reader.Read())
                    {
                        //Skip until element
                        if (reader.NodeType == XmlNodeType.Whitespace)
                        {
                            continue;
                        }
                        if (reader.NodeType == XmlNodeType.XmlDeclaration)
                        {
                            continue;
                        }
                        if (reader.NodeType != XmlNodeType.Element)
                        {
                            Debug.WriteLine("Unhandled node {0} {1} {2}", reader.NodeType, reader.Name, reader.Value);
                            continue;
                        }

                        var typeArguments = XamlParser.GetTypeArguments(reader);
                        var rootnode      = new RuntimeRootNode(new XmlType(reader.NamespaceURI, reader.Name, typeArguments), null, (IXmlNamespaceResolver)reader)
                        {
                            LineNumber = ((IXmlLineInfo)reader).LineNumber, LinePosition = ((IXmlLineInfo)reader).LinePosition
                        };

                        XamlParser.ParseXaml(rootnode, reader);
                        var visitorContext = new HydrationContext
                        {
                            ExceptionHandler = doNotThrow ? ehandler : (Action <Exception>)null,
                        };
                        var cvv = new CreateValuesVisitor(visitorContext);
                        cvv.Visit((ElementNode)rootnode, null);
                        inflatedView = rootnode.Root = visitorContext.Values[rootnode];
                        visitorContext.RootElement = inflatedView as BindableObject;

                        Visit(rootnode, visitorContext, useDesignProperties);
                        VisualDiagnostics.OnChildAdded(null, inflatedView as Element);
                        break;
                    }
                }
            return(inflatedView);
        }
Ejemplo n.º 4
0
        protected override void SetupContent(Cell content, int index)
        {
            base.SetupContent(content, index);
            if (content is ViewCell viewCell && viewCell.View != null && HasUnevenRows)
            {
                viewCell.View.ComputedConstraint = LayoutConstraint.None;
            }

            if (content != null)
            {
                _logicalChildren.Add(content);
            }

            content.Parent = this;
            VisualDiagnostics.OnChildAdded(this, content);
        }
Ejemplo n.º 5
0
        public static void Load(object view, string xaml, Assembly rootAssembly, bool useDesignProperties)
        {
            using (var textReader = new StringReader(xaml))
                using (var reader = XmlReader.Create(textReader))
                {
                    while (reader.Read())
                    {
                        //Skip until element
                        if (reader.NodeType == XmlNodeType.Whitespace)
                        {
                            continue;
                        }
                        if (reader.NodeType == XmlNodeType.XmlDeclaration)
                        {
                            continue;
                        }
                        if (reader.NodeType != XmlNodeType.Element)
                        {
                            Debug.WriteLine("Unhandled node {0} {1} {2}", reader.NodeType, reader.Name, reader.Value);
                            continue;
                        }

                        var rootnode = new RuntimeRootNode(new XmlType(reader.NamespaceURI, reader.Name, null), view, (IXmlNamespaceResolver)reader)
                        {
                            LineNumber = ((IXmlLineInfo)reader).LineNumber, LinePosition = ((IXmlLineInfo)reader).LinePosition
                        };
                        XamlParser.ParseXaml(rootnode, reader);
#pragma warning disable 0618
                        var doNotThrow = ResourceLoader.ExceptionHandler2 != null || Internals.XamlLoader.DoNotThrowOnExceptions;
#pragma warning restore 0618
                        void ehandler(Exception e) => ResourceLoader.ExceptionHandler2?.Invoke((e, XamlFilePathAttribute.GetFilePathForObject(view)));

                        Visit(rootnode, new HydrationContext
                        {
                            RootElement      = view,
                            RootAssembly     = rootAssembly ?? view.GetType().GetTypeInfo().Assembly,
                            ExceptionHandler = doNotThrow ? ehandler : (Action <Exception>)null
                        }, useDesignProperties);

                        VisualDiagnostics.OnChildAdded(null, view as Element);

                        break;
                    }
                }
        }