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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:45:22+00:00 2026-05-15T17:45:22+00:00

I have a function with one string parameter. Parameter is the name of existing

  • 0

I have a function with one string parameter. Parameter is the name of existing wpf Window’s name. Now i want to create a instance of window by string parameter and want to call Show() function of that window.

  • 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-15T17:45:22+00:00Added an answer on May 15, 2026 at 5:45 pm

    It depends on whether the name you are given is the filename the window is defined in or the class name. Usually these are the same, but they can be different.

    For example you might put the following in a file called “Elephant.xaml”:

    <Window x:Class="Animals.Pachyderm" ...>
      ...
    </Window>
    

    If you do so, then the filename of the window is “Elephant.xaml” but the class name is “Pachyderm” in namespace “Animals”.

    Loading a window given the file name

    To instantiate and show a window given the filename:

    var window = (Window)Application.LoadComponent(new Uri("Elephant.xaml", UriKind.Relative));
    window.Show();
    

    So your method would look something like this:

    void ShowNamedWindow(string windowFileName)
    {
      var window = (Window)Application.LoadComponent(new Uri(windowFileName + ".xaml", UriKind.Relative));
      window.Show();
    }
    

    And be called like this:

    ShowNamedWindow("Elephant");
    

    Loading a window given the class name

    To instantiate and show a window given the class name:

    var window = (Window)Activator.CreateInstance(Type.GetType("Animals.Pachyderm"));
    

    So your method would look something like this:

    void ShowNamedWindow(string className)
    {
      var window = (Window)Activator.CreateInstance(Type.GetType("Animals." + className));
      window.Show();
    }
    

    And be called like this:

    ShowNamedWindow("Pachyderm");
    

    Alternatively you could include the namespace (“Animals” in this example) in the parameter to ShowNamedWindow instead of appending it inside the method.

    Loading a window given only the title

    This is not recommended, since it could be a very costly operation. You would need to get the Assembly, iterate all the types in the Assembly that are a subclass of Window, instantiate each one, and extract its Title property. This would actually construct (but not show) one of each kind of window in your application until it found the right one. So I would use the filename or class name if at all possible.

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

Sidebar

Related Questions

I have one function ParseHtmlTable(string htmlContent) . Now in that function I want to
I have a function written in C# which has one parameter type as Dictionary<string
I have a ComboBox with a label function like this one: private function fieldLabelFunction(item:Object):String
I have one function for one element: <a href=javascript:void(0); onclick=dothis()>Link</a> When this function is
I have following function in one Activity public void AppExit() { Editor edit =
I'm trying to get rid of floats in my functions. I have one function
I have made one function in which I am passing a matrix and returning
I have one constructor function, which acts as a superclass: Bla = function(a){this.a =
I have one javascript function that used to display the menu and content in
One question for you is here ;) I have this function: function Set-DbFile {

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.