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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:49:36+00:00 2026-06-07T18:49:36+00:00

I know how to create a dynamic control in c#: TextBlock tb = new

  • 0

I know how to create a dynamic control in c#:

TextBlock tb = new TextBlock();
tb.Text = "This is a new textblock";

But how would I reference this newly created control through code?
I browsed the net for a solution, and came across this code:

TextBlock tb = (TextBlock)this.FindName("TB");
tb.Text = "Text property changed"; 

Every time I create a new control with a name I get an exception:

TextBlock tb = new TextBlock();
tb.Text = "This is a new textblock";
tb.Name = "TB";

“The parameter is incorrect.”

What am I doing wrong? Any help would be greatly appreciated.

Thanks in advance.

  • 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-07T18:49:37+00:00Added an answer on June 7, 2026 at 6:49 pm

    The Exception “The parameter is incorrect.” may be occurring because of the duplicate names of the controls created.

    For the dynamic control part : you must be adding that control to some Grid or Stackpanel or something. you can reference that dynamic control by getting the content or children of the parent control.

    Like :

    TextBlock Tb= new TextBlock();
    tb.Text = "Hello";
    
    ContentPanel.Children.Add(Tb);
    

    //to reference :

    var content = ContentPanel.Children;
    foreach(UIElement uiElem in content)
    {
      if(uiElem.GetType() == typeof(TextBlock))
      {
         TextBlock tb = uiElem as TextBlock;
         tb.Text = "Hyee";
      }
    }
    

    Hope, it might help.

    (Note: I have written this code directly here and not copied from VS, so please check syntax and spellings.)

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

Sidebar

Related Questions

I would like to know how can I create a 'dynamic intent' in android.
I want to create dynamic content based on this. I know it's somewhere, as
I know how to create a dynamic method by injecting IL for say a
I know I can create a List<T> from IEnumerable<T> by doing myEnumerableCollection.ToList() , but
I know how to create a job dynamically from this create-sql-server-job-automatically The issue I
Anyone know of some good gems or plugins to create dynamic / ajax crud
I created a page in ASP that loads dynamic content with code similar to
I want to know how to create dynamic table in mySql . I have
how can i create a dynamic frequency graph in android? like this: http://www.jazzitalia.net/lezioni/sax/immagini/grafico1.gif without
I would like to create a dynamic proxy for binding WinForms controls to objects

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.