void IMauiContainerElementHandler.AddChild(MC.Element child, int physicalSiblingIndex)
        {
            var index = Math.Min(physicalSiblingIndex, Elements.Count);

            Elements.Insert(index, child);
            ChildAdded?.Invoke(child);
        }
Exemplo n.º 2
0
 public virtual void RemoveChild(MC.Element child)
 {
     if (ContentPageControl.Content == child)
     {
         ContentPageControl.Content = null;
     }
 }
Exemplo n.º 3
0
 public virtual void RemoveChild(MC.Element child)
 {
     if (ShellContentControl.Content == child)
     {
         ShellContentControl.Content = null;
     }
 }
Exemplo n.º 4
0
        public virtual void AddChild(MC.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            MC.ShellItem itemToAdd = child switch
            {
                MC.TemplatedPage childAsTemplatedPage => childAsTemplatedPage,       // Implicit conversion
                         MC.ShellContent childAsShellContent => childAsShellContent, // Implicit conversion
                         MC.ShellSection childAsShellSection => childAsShellSection, // Implicit conversion
                         MC.MenuItem childAsMenuItem => childAsMenuItem,             // Implicit conversion
                         MC.ShellItem childAsShellItem => childAsShellItem,
                         _ => throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support adding a child (child type is '{child.GetType().FullName}').")
            };

            if (ShellControl.Items.Count >= physicalSiblingIndex)
            {
                ShellControl.Items.Insert(physicalSiblingIndex, itemToAdd);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but ShellControl.Items.Count={ShellControl.Items.Count}");
                ShellControl.Items.Add(itemToAdd);
            }
        }
 public void RemoveChild(MC.Element child)
 {
     if (ScrollViewControl.Content == child)
     {
         ScrollViewControl.Content = null;
     }
 }
Exemplo n.º 6
0
 private MC.ShellContent GetContentForChild(MC.Element child)
 {
     return(child switch
     {
         MC.TemplatedPage childAsTemplatedPage => GetContentForTemplatePage(childAsTemplatedPage),
         MC.ShellContent childAsShellContent => childAsShellContent,
         _ => null
     });
Exemplo n.º 7
0
 public override void SetParent(MC.Element parent)
 {
     if (ElementControl.Parent == null)
     {
         // The Parent should already be set
         throw new InvalidOperationException("Shouldn't need to set parent here...");
     }
 }
 public int GetChildIndex(MC.Element child)
 {
     // Not sure whether elements "order" matters here
     return(child switch
     {
         _ when child == FlyoutPageControl.Flyout => 0,
         _ when child == FlyoutPageControl.Detail => 1,
         _ => - 1
     });
Exemplo n.º 9
0
        public int GetChildIndex(MC.Element child)
        {
            if (!(child is MC.View childView))
            {
                return(-1);
            }

            return(_children.IndexOf(childView));
        }
        public void RemoveChild(MC.Element child)
        {
            if (!(child is MC.GradientStop gradientStopChild))
            {
                throw new ArgumentException($"GradientBrush support GradientStop child elements only, but {child?.GetType()} found instead.", nameof(child));
            }

            GradientBrushControl.GradientStops.Remove(gradientStopChild);
        }
Exemplo n.º 11
0
 private MC.ShellSection GetSectionForElement(MC.Element child)
 {
     return(child switch
     {
         MC.TemplatedPage childAsTemplatedPage => GetSectionForTemplatedPage(childAsTemplatedPage),
         MC.ShellContent childAsShellContent => GetSectionForContent(childAsShellContent),
         MC.ShellSection childAsShellSection => childAsShellSection,
         _ => null
     });
Exemplo n.º 12
0
        void IMauiContainerElementHandler.AddChild(MC.Element child, int physicalSiblingIndex)
        {
            if (!(child is TItemType typedChild))
            {
                throw new NotSupportedException($"Cannot add item of type {child?.GetType().Name} to a {typeof(TItemType)} collection.");
            }

            _propertyItems.Insert(physicalSiblingIndex, typedChild);
        }
        public int GetChildIndex(MC.Element child)
        {
            if (!(child is MC.GradientStop gradientStopChild))
            {
                throw new ArgumentException($"GradientBrush support GradientStop child elements only, but {child?.GetType()} found instead.", nameof(child));
            }

            return(GradientBrushControl.GradientStops.IndexOf(gradientStopChild));
        }
Exemplo n.º 14
0
        public void RemoveChild(MC.Element child)
        {
            if (!(child is MC.View childView))
            {
                throw new ArgumentException($"Expected parent to be of type {typeof(MC.View).FullName} but it is of type {child?.GetType().FullName}.", nameof(child));
            }

            _children.Remove(childView);
            _parentGrid.Children.Remove(childView);
        }
Exemplo n.º 15
0
 private MC.ShellItem GetItemForElement(MC.Element child)
 {
     return(child switch
     {
         MC.TemplatedPage childAsTemplatedPage => GetItemForTemplatedPage(childAsTemplatedPage),
         MC.ShellContent childAsShellContent => GetItemForContent(childAsShellContent),
         MC.ShellSection childAsShellSection => GetItemForSection(childAsShellSection),
         MC.MenuItem childAsMenuItem => GetItemForMenuItem(childAsMenuItem),
         MC.ShellItem childAsShellItem => childAsShellItem,
         _ => null
     });
        public Task <TComponent> AddComponent <TComponent>(MC.Element parent, Dictionary <string, object> parameters = null) where TComponent : IComponent
        {
            if (parent is MC.Application app)
            {
                app.MainPage ??= new MC.ContentPage();
            }

            var handler = CreateHandler(parent, this);

            return(AddComponent <TComponent>(handler, parameters));
        }
Exemplo n.º 17
0
        public virtual void RemoveChild(MC.Element child)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            var itemToRemove = GetItemForElement(child)
                               ?? throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support removing a child (child type is '{child.GetType().FullName}').");

            ShellControl.Items.Remove(itemToRemove);
        }
Exemplo n.º 18
0
        public int GetChildIndex(MC.Element child)
        {
            // There are two cases to consider:
            // 1. A Xamarin.Forms Label can have only 1 child (a FormattedString), so the child's index is always 0.
            // 2. But to simplify things, in MobileBlazorBindings a Label can contain a Span directly, so if the child
            //    is a Span, we have to compute its sibling index.

            return(child switch
            {
                MC.Span span => LabelControl.FormattedText?.Spans.IndexOf(span) ?? -1,
                MC.FormattedString formattedString when LabelControl.FormattedText == formattedString => 0,
                _ => - 1
            });
Exemplo n.º 19
0
        public virtual void AddChild(MC.Element child, int physicalSiblingIndex)
        {
            var childAsView = child as IView;

            if (physicalSiblingIndex <= LayoutControl.Children.Count)
            {
                LayoutControl.Children.Insert(physicalSiblingIndex, childAsView);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but layoutControlOfView.Children.Count={LayoutControl.Children.Count}");
                LayoutControl.Children.Add(childAsView);
            }
        }
        public virtual void AddChild(MC.Element child, int physicalSiblingIndex)
        {
            var childAsPage = child as MC.Page;

            if (physicalSiblingIndex <= TabbedPageControl.Children.Count)
            {
                TabbedPageControl.Children.Insert(physicalSiblingIndex, childAsPage);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but TabbedPageControl.Children.Count={TabbedPageControl.Children.Count}");
                TabbedPageControl.Children.Add(childAsPage);
            }
        }
Exemplo n.º 21
0
        public void AddChild(MC.Element child, int physicalSiblingIndex)
        {
            if (!(child is MC.View childView))
            {
                throw new ArgumentException($"Expected parent to be of type {typeof(MC.View).FullName} but it is of type {child?.GetType().FullName}.", nameof(child));
            }

            MC.Grid.SetColumn(childView, Column);
            MC.Grid.SetColumnSpan(childView, ColumnSpan);
            MC.Grid.SetRow(childView, Row);
            MC.Grid.SetRowSpan(childView, RowSpan);

            _children.Add(childView);
            _parentGrid.Children.Add(childView);
        }
 private static ElementHandler CreateHandler(MC.Element parent, MobileBlazorBindingsRenderer renderer)
 {
     return(parent switch
     {
         MC.ContentPage contentPage => new ContentPageHandler(renderer, contentPage),
         MC.ContentView contentView => new ContentViewHandler(renderer, contentView),
         MC.Label label => new LabelHandler(renderer, label),
         MC.FlyoutPage flyoutPage => new FlyoutPageHandler(renderer, flyoutPage),
         MC.ScrollView scrollView => new ScrollViewHandler(renderer, scrollView),
         MC.ShellContent shellContent => new ShellContentHandler(renderer, shellContent),
         MC.Shell shell => new ShellHandler(renderer, shell),
         MC.ShellItem shellItem => new ShellItemHandler(renderer, shellItem),
         MC.ShellSection shellSection => new ShellSectionHandler(renderer, shellSection),
         MC.TabbedPage tabbedPage => new TabbedPageHandler(renderer, tabbedPage),
         _ => new ElementHandler(renderer, parent),
     });
Exemplo n.º 23
0
        public virtual void AddChild(MC.Element child, int physicalSiblingIndex)
        {
            var childAsSpan = child as MC.Span;

            var formattedString = GetFormattedString();

            if (physicalSiblingIndex <= formattedString.Spans.Count)
            {
                formattedString.Spans.Insert(physicalSiblingIndex, childAsSpan);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but Label.FormattedText.Spans.Count={LabelControl.FormattedText.Spans.Count}");
                formattedString.Spans.Add(childAsSpan);
            }
        }
        public void AddChild(MC.Element child, int physicalSiblingIndex)
        {
            if (!(child is MC.GradientStop gradientStopChild))
            {
                throw new ArgumentException($"GradientBrush support GradientStop child elements only, but {child?.GetType()} found instead.", nameof(child));
            }

            if (physicalSiblingIndex <= GradientBrushControl.GradientStops.Count)
            {
                GradientBrushControl.GradientStops.Insert(physicalSiblingIndex, gradientStopChild);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but GradientBrushControl.GradientStops.Count={GradientBrushControl.GradientStops}");
                GradientBrushControl.GradientStops.Add(gradientStopChild);
            }
        }
        public virtual void AddChild(MC.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            if (child is FlyoutFlyoutPageContentPage masterPage)
            {
                FlyoutPageControl.Flyout = masterPage;
            }
            else if (child is FlyoutDetailPageContentPage detailPage)
            {
                FlyoutPageControl.Detail = detailPage;
            }
            else
            {
                throw new InvalidOperationException($"Unknown child type {child.GetType().FullName} being added to parent element type {GetType().FullName}.");
            }
        }
        public virtual void RemoveChild(MC.Element child)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            if (child == FlyoutPageControl.Flyout)
            {
                FlyoutPageControl.Flyout = new MC.Page()
                {
                    Title = "Title"
                };
            }
            else if (child == FlyoutPageControl.Detail)
            {
                FlyoutPageControl.Detail = new MC.Page();
            }
            else
            {
                throw new InvalidOperationException($"Unknown child type {child.GetType().FullName} being removed from parent element type {GetType().FullName}.");
            }
        }
Exemplo n.º 27
0
 public virtual void SetParent(MC.Element parent)
 {
     ElementControl.Parent = parent;
 }
Exemplo n.º 28
0
 public virtual bool IsParentedTo(MC.Element parent)
 {
     return(ElementControl.Parent == parent);
 }
Exemplo n.º 29
0
 public ElementHandler(NativeComponentRenderer renderer, MC.Element elementControl)
 {
     Renderer       = renderer ?? throw new ArgumentNullException(nameof(renderer));
     ElementControl = elementControl ?? throw new ArgumentNullException(nameof(elementControl));
 }
 void IMauiElementHandler.SetParent(MC.Element parent)
 {
 }