コード例 #1
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);
        }
コード例 #2
0
        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}.");
            }
        }
コード例 #3
0
        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}.");
            }
        }
コード例 #4
0
ファイル: Binding.cs プロジェクト: josephwambura/maui
        bool ElementFitsAncestorTypeAndLevel(Element element, ref int level, ref object lastPotentialBctx)
        {
            if (!(Source is RelativeBindingSource relativeSource))
            {
                return(false);
            }

            bool fitsElementType =
                relativeSource.Mode == RelativeBindingSourceMode.FindAncestor &&
                relativeSource.AncestorType.GetTypeInfo().IsAssignableFrom(element.GetType().GetTypeInfo());

            bool fitsBindingContextType =
                element.BindingContext != null &&
                relativeSource.Mode == RelativeBindingSourceMode.FindAncestorBindingContext &&
                relativeSource.AncestorType.GetTypeInfo().IsAssignableFrom(element.BindingContext.GetType().GetTypeInfo());

            if (!fitsElementType && !fitsBindingContextType)
            {
                return(false);
            }

            if (fitsBindingContextType)
            {
                if (!object.ReferenceEquals(lastPotentialBctx, element.BindingContext))
                {
                    lastPotentialBctx = element.BindingContext;
                    level++;
                }
            }
            else
            {
                level++;
            }

            return(level >= relativeSource.AncestorLevel);
        }
コード例 #5
0
ファイル: Device.cs プロジェクト: hevey/maui
 public static double GetNamedSize(NamedSize size, Element targetElement)
 {
     return(GetNamedSize(size, targetElement.GetType()));
 }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
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);
        }
コード例 #12
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);
            }
        }