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); } }
private XF.ShellContent GetContentForChild(XF.Element child) { return(child switch { XF.TemplatedPage childAsTemplatedPage => GetContentForTemplatePage(childAsTemplatedPage), XF.ShellContent childAsShellContent => childAsShellContent, _ => null });
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 });
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 });
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); }
public TemplatedPageHandler(NativeComponentRenderer renderer, XF.TemplatedPage templatedPageControl) : base(renderer, templatedPageControl) { TemplatedPageControl = templatedPageControl ?? throw new ArgumentNullException(nameof(templatedPageControl)); Initialize(renderer); }
private XF.ShellContent GetContentForTemplatePage(XF.TemplatedPage childAsTemplatedPage) { return(ShellSectionControl.Items.FirstOrDefault(content => content.Content == childAsTemplatedPage)); }
private XF.ShellSection GetSectionForTemplatedPage(XF.TemplatedPage templatedPage) { return(ShellItemControl.Items .FirstOrDefault(section => section.Items.Any(contect => contect.Content == templatedPage))); }
private XF.ShellItem GetItemForTemplatedPage(XF.TemplatedPage childAsTemplatedPage) { return(ShellControl.Items .FirstOrDefault(item => item.Items .Any(section => section.Items.Any(content => content.Content == childAsTemplatedPage)))); }