How do I use an existing element as content for every new tabview item?

Hemanth B 886 Reputation points
2022-10-05T13:15:30.087+00:00

Hi I am using C# WinUI 3 WinAppSDK for my app.
I have a tab view with add tabs option and i also have a home page panel which is collapsed at general state.
Now whenever the user adds a new tab, I want the same home page to appear as its content instead of programmatically adding each element in the tabview item.
When I set this:
newItem.Content = homepagegrid;

I get this error:
System.ArgumentException: 'Value does not fall within the expected range.'

Windows development Windows App SDK
0 comments No comments
{count} vote

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2022-10-06T08:00:35.083+00:00

    Hello @Hemanth B
    Welcome to Microsoft Q&A!

    Have you read this document Create a tab view?

    I also encountered the same problem when adding a panel to the TabView, you can write the panel into a page and then add this page to the content of the tabview.

    Frame frame = new Frame();  
    newTab.Content = frame;  
    frame.Navigate(typeof(Page1));  
    

    Thank you.
    Junjie


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.