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 812197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:09:58+00:00 2026-05-15T01:09:58+00:00

I have a custom built menu system in which I would like to load

  • 0

I have a custom built menu system in which I would like to load user controls from another project into a tab control on my main project (menu control)

User control Project : foobar
Menu system Project : Menu

The function to load them into the tab control:

private void LaunchWPFApplication(string header, string pPath)
        {
            // Header - What loads in the tabs header portion.
            // pPath   - Page where to send the user

            //Create a new browser tab object
            BrowserTab bt = tabMain.SelectedItem as BrowserTab;
            bt = new BrowserTab();
            bt.txtHeader.Text = header;
            bt.myParent = BrowserTabs;

             //Load in the path 
        try
        {
            Type formType = Type.GetType(pPath, true);
            bt.Content = (UserControl)Activator.CreateInstance(formType);
        }
        catch
        {
            MessageBox.Show("The specified user control : " + pPath + " cannot be found");
        }

            //Add the browser tab and then focus            
            BrowserTabs.Add(bt);
            bt.IsSelected = true;
        }

And what I send to the function as an example:

LaunchWPFApplication("Calculater", "foobar.AppCalculater");

But every time run, the application complains that the formType is null. I am confused on how to load the user control and curious if I’m sending the correct parameters.

  • 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-05-15T01:09:58+00:00Added an answer on May 15, 2026 at 1:09 am

    The problem I had was in calling the Type.GetType. The generic call which the MSDN gives is

    Type formType = Type.GetType("AppCalculater");
    

    which calls get the type of the specified name. This would still no matter what return a null. I then added the namespace to the mix.

    Type formType = Type.GetType("foobar.AppCalculater");
    

    This however was still giving me an error calling the other project files in foobar. To get the user controls in the other project, I added the assembly after the control and namespace call.

    Type formType = Type.GetType("foobar.AppCalculater,foobar");
    

    I then was able to reference all the user controls dynamically using this call. Thus my now updated call to load a user control from another project into my tab control is as follows :

    private void LaunchWPFApplication(string header, string pPath)
            {
                // Header - What loads in the tabs top portion.
                // Path   - Page where to send the user
    
                //Create a new browser tab object
                BrowserTab bt = tabMain.SelectedItem as BrowserTab;
                bt = new BrowserTab();
                bt.txtHeader.Text = header;
                bt.myParent = BrowserTabs;
    
                //Load in the path 
                try
                {
                    Type formType = Type.GetType(pPath); //Example "foobar.foobarUserControl,foobar"
                    bt.Content = Activator.CreateInstance(formType);
                }
                catch (ArgumentNullException)
                {
                    MessageBox.Show("The specified user control : " + pPath + " cannot be found");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error has occurred while loaded the specified user control : " + pPath + ". It includes the following message : \n" + ex);
                }
                //Add the browser tab and then focus     
                try
                {
                    BrowserTabs.Add(bt);
                }
                catch(InvalidOperationException)
                {
                    MessageBox.Show("Cannot add " + pPath + " into the tab control");
                }
                bt.IsSelected = true;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.