コード例 #1
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);
            }
        }
コード例 #2
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
     });