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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:05:46+00:00 2026-05-27T17:05:46+00:00

I am reading in an XML file and using it to populate a WPF

  • 0

I am reading in an XML file and using it to populate a WPF Form. Each entry in the XML file is used to create a button and a label.

The problem I am having is associating the button with the label:

Here is my code:

// Loop through Backups
foreach (var back in backups)
{
    // Create Wrap Panel
    myWrapPanel = new WrapPanel();
    //myWrapPanel.Background = System.Windows.Media.Brushes.Red;
    myWrapPanel.Orientation = System.Windows.Controls.Orientation.Horizontal;
    myWrapPanel.Width = 600;
    myWrapPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
    myWrapPanel.VerticalAlignment = System.Windows.VerticalAlignment.Top;

    // **************************************
    // Add Controls to Wrap Panel
    // **************************************
    // Backup Source
    System.Windows.Controls.Button btnBackupSource = new System.Windows.Controls.Button();
    btnBackupSource.Content = "Source";
    btnBackupSource.Height = 25;
    btnBackupSource.Width = 75;
    btnBackupSource.Click += btnBackupSource_Click;
    btnBackupSource.Name = "btnBackupSource";
    myWrapPanel.Children.Add(btnBackupSource);

    System.Windows.Controls.Label lblBackupSource = new System.Windows.Controls.Label();
    lblBackupSource.Height = 25;
    lblBackupSource.Width = 461;
    lblBackupSource.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
    lblBackupSource.VerticalAlignment = System.Windows.VerticalAlignment.Top;
    lblBackupSource.Name = "lblBackupSource";
    lblBackupSource.Content = "";
    myWrapPanel.Children.Add(lblBackupSource);

The button and labels are created OK but I am struggling to associate them with each other. For example when a button is pressed the result needs to come up in the individual label which is associated with the button.

Any suggestions on how to proceed would be very welcome!

What I have currently got is each button updating a single label:

private void btnBackupSource_Click(object sender, RoutedEventArgs e)
    {
        SourceFolderBrowser = new System.Windows.Forms.FolderBrowserDialog();
        // Allow users to creating new folders and default to the my documents folder.
        SourceFolderBrowser.ShowNewFolderButton = true;
        SourceFolderBrowser.RootFolder = Environment.SpecialFolder.Personal;

        SourceFolderBrowser.ShowDialog();

        label2.Content = SourceFolderBrowser.SelectedPath;
    }

However what I am trying to do is get each button to update its associated label.

  • 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-27T17:05:47+00:00Added an answer on May 27, 2026 at 5:05 pm

    Here is my suggestion for you:

    Store the label you want to associate with the button in the button’s Tag property like this:

    btnBackupSource.Tag = lblBackupSource;
    

    Later when you to do something in the wired up btnBackupSource_Click you can do it like this:

    var button = sender as Button;
    var label = button.Tag as Label;
    label.Text = "Hello";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a dynamic menu by reading an XML file using
I am facing problem for reading xml file using javascript. It works fine in
I am reading an xml file using javascript and then I need to submit
I'm using Qt C++ and am reading in an XML file for data. I
what is the best way of reading xml file using linq and the below
I am reading an XML file using an XMLTextReader. Is there a way to
I'm reading a large xml file using HttpURLConnection in java as follows. StringBuilder responseBuilder
Im using Crytal report WPF Application to generate a report with xml file and
I have a problem reading OWL/XML files from Java using Jena. I have no
I am studying Linq to xml and i am reading a xml file using

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.