Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8572641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:04:01+00:00 2026-06-11T19:04:01+00:00

I am attempting to populate a grid in my MainPage with web browser items

  • 0

I am attempting to populate a grid in my MainPage with web browser items which are added in the code behind. For some reason, I cannot get the grid to remember which elements have been added already. I am unsure of how to store this information so that when the MainPage is navigated from, and then back to, the grid knows which values were previously added. To better explain, what I have is as follows:

MainPage.xaml

<Grid x:Name="BrowserHost" Grid.Row="1">
    //Items will be added in code behind
</Grid>

MainPage.xaml.cs

private void ShowTab(int index) 
    {
        this.currentIndex = index;
        int count = Settings.BrowserList.Value.Count;

        if (count <= 0)
        {                
            MessageBox.Show("count <= 0");
        }
        if (currentIndex <= (count - 1))  //in correct range
        {
            // BrowserHost does not remember previously added children elements added previously when navigated back to this page and performing this check
            if(!BrowserHost.Children.Contains(Settings.BrowserList.Value[currentIndex].Browser))
                //Attempt to add browser if it was already added previously throws InvalidOperationException
                BrowserHost.Children.Add(Settings.BrowserList.Value[currentIndex].Browser);
        }

        if (currentIndex > (count - 1))
        {
            MessageBox.Show("currentIndex > (count - 1)");
        }

        for (int i = 0; i < Settings.BrowserList.Value.Count; i++)
        {
            if (Settings.BrowserList.Value.ElementAt(i) != null)
            {
                Settings.BrowserList.Value.ElementAt(i).Browser.Visibility = i == this.currentIndex ? Visibility.Visible : Visibility.Collapsed;
            }
        }
    }

Essentially, the ShowTab method is called with a specific index value everytime the MainPage loads. A check is performed to see if Settings.BrowserList.Value[currentIndex].Browser (a collection with web browser instances) exists at the currentIndex in the list (these are added in another page). If the BrowserHost grid on MainPage already contains the child element (a browser) with a particular index, then it should skip over the check and continue to show that browser instance on the screen. This is supposed to basically implement a tabbed browsing scenario for a custom web browser control I have created. My issue is, I can consecutively add new browsers to BrowserHost and show them on the screen, but when I try to call a previously added webbrowser at certain index in my collection, I get an InvalidOperationException. How would I fix this? My debugging shows that in ShowTab when I check to see if a browser has been added, regardless of it has or not, it jumps into attempting to add that browser to BrowserHost child element. If the browser has been created previously, thats when the InvalidOperationException occurs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:04:02+00:00Added an answer on June 11, 2026 at 7:04 pm

    I don’t think what you are doing is a good idea. However, the issue seems to be that the control is already parented by a different control and so you cannot add it again. Try doing the following:

    var browser = Settings.BrowserList.Value[currentIndex].Browser;
    if(!BrowserHost.Children.Contains(browser))
    {
    
      var grid = (Grid)browser.Parent;
      if (grid != null)
      {
        grid.Children.Remove(browser);
      }
      BrowserHost.Children.Add(browser);
    }
    

    You also need to make sure that the Browser is placed in a Grid in your other form (if it’s not directly inside a Grid, just wrap it in one).

    This may work, but I strongly suggest you find a different way of doing it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue where I cannot seem to get the values to re-populate
I am attempting to populate an ObservableCollection with the currently selected items in a
I am attempting following code to populate an UnOrdered List dynamically. The same type
I'm attempting to get Python to populate the lists with the closing prices of
I'm attempting to dynamically construct some classes which are subclasses of django's models.Model. My
While attempting to populate the items in a ListView following the outcome of a
I am attempting to populate A2:A13 with the months of the year. Obviously I
I am attempting to populate a list of records within the last X seconds
I’m attempting to use the values from one JSON link to populate values in
I am attempting to create a ListView control which is populated via a binding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.