コード例 #1
0
        public virtual void AddChild(XF.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            XF.ShellSection sectionToAdd = child switch
            {
                XF.TemplatedPage childAsTemplatedPage => childAsTemplatedPage,          // Implicit conversion
                            XF.ShellContent childAsShellContent => childAsShellContent, // Implicit conversion
                            XF.ShellSection childAsShellSection => childAsShellSection,
                            _ => 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 (ShellItemControl.Items.Count >= physicalSiblingIndex)
            {
                ShellItemControl.Items.Insert(physicalSiblingIndex, sectionToAdd);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but ShellItemControl.Items.Count={ShellItemControl.Items.Count}");
                ShellItemControl.Items.Add(sectionToAdd);
            }
        }
コード例 #2
0
 private XF.ShellContent GetContentForChild(XF.Element child)
 {
     return(child switch
     {
         XF.TemplatedPage childAsTemplatedPage => GetContentForTemplatePage(childAsTemplatedPage),
         XF.ShellContent childAsShellContent => childAsShellContent,
         _ => null
     });
コード例 #3
0
 private XF.ShellSection GetSectionForElement(XF.Element child)
 {
     return(child switch
     {
         XF.TemplatedPage childAsTemplatedPage => GetSectionForTemplatedPage(childAsTemplatedPage),
         XF.ShellContent childAsShellContent => GetSectionForContent(childAsShellContent),
         XF.ShellSection childAsShellSection => childAsShellSection,
         _ => null
     });
コード例 #4
0
 private XF.ShellItem GetItemForElement(XF.Element child)
 {
     return(child switch
     {
         XF.TemplatedPage childAsTemplatedPage => GetItemForTemplatedPage(childAsTemplatedPage),
         XF.ShellContent childAsShellContent => GetItemForContent(childAsShellContent),
         XF.ShellSection childAsShellSection => GetItemForSection(childAsShellSection),
         XF.MenuItem childAsMenuItem => GetItemForMenuItem(childAsMenuItem),
         XF.ShellItem childAsShellItem => childAsShellItem,
         _ => null
     });
コード例 #5
0
        public virtual void RemoveChild(XF.Element child)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            XF.ShellContent contentToRemove = child switch
            {
                XF.TemplatedPage childAsTemplatedPage => GetContentForTemplatePage(childAsTemplatedPage),
                XF.ShellContent childAsShellContent => childAsShellContent,
                _ => 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}').")
            };

            ShellSectionControl.Items.Remove(contentToRemove);
        }
コード例 #6
0
        public TemplatedPageHandler(NativeComponentRenderer renderer, XF.TemplatedPage templatedPageControl) : base(renderer, templatedPageControl)
        {
            TemplatedPageControl = templatedPageControl ?? throw new ArgumentNullException(nameof(templatedPageControl));

            Initialize(renderer);
        }
コード例 #7
0
 private XF.ShellContent GetContentForTemplatePage(XF.TemplatedPage childAsTemplatedPage)
 {
     return(ShellSectionControl.Items.FirstOrDefault(content => content.Content == childAsTemplatedPage));
 }
コード例 #8
0
 private XF.ShellSection GetSectionForTemplatedPage(XF.TemplatedPage templatedPage)
 {
     return(ShellItemControl.Items
            .FirstOrDefault(section => section.Items.Any(contect => contect.Content == templatedPage)));
 }
コード例 #9
0
 private XF.ShellItem GetItemForTemplatedPage(XF.TemplatedPage childAsTemplatedPage)
 {
     return(ShellControl.Items
            .FirstOrDefault(item => item.Items
                            .Any(section => section.Items.Any(content => content.Content == childAsTemplatedPage))));
 }