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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:15:19+00:00 2026-06-02T09:15:19+00:00

This might sound strange at first but its rather simple. I have a wcf

  • 0

This might sound strange at first but its rather simple. I have a wcf webservice (restful) in this service I have set some generic “user” fields and one of the fields which I have set is the userID to increment every time a user is added. All pretty simple stuff.

I then have a consuming wpf application. For each of the users mentioned above in my webservice I dynamically set out content to hold each of those users in my wpf application which is done on button click, this then loads the content area with groupboxs and textblocks neatly arranged (again pretty simple). The containers I hold them in are GroupBox.Header which holds the userID and Textblock which equals the students first name and last name.

Like so:

private void button1_Click(object sender, RoutedEventArgs e)
        {

            if (string.IsNullOrEmpty(textBox1.Text))
            {
                PanelMainContent.Children.Clear();
                MainArea1.Children.Clear();
                string uriGroups = "http://localhost:8000/Service/Student";
                XDocument xDoc = XDocument.Load(uriGroups);
                var sortedXdoc = xDoc.Descendants("Student")
                               .OrderByDescending(x => Convert.ToDateTime(x.Element("TimeAdded").Value));
                foreach (var node in xDoc.Descendants("Student").OrderByDescending(x => Convert.ToDateTime(x.Element("TimeAdded").Value)))
                {

                    GroupBox groupbox = new GroupBox();
                    groupbox.Header = String.Format(node.Element("StudentID").Value);
                    App.Current.Properties["groupboxHeader"] = groupbox.Header;
                    groupbox.Width = 100;
                    groupbox.Height = 100;
                    groupbox.Margin = new Thickness(1);

                    Button btnFindStudent = new Button();
                    btnFindStudent.Click += this.btnGeneral_Click;
                    btnFindStudent.Name = Convert.ToString("btnViewStudent");
                    btnFindStudent.Tag = Convert.ToString("ViewStudent");
                    btnFindStudent.Content = Convert.ToString("View");
                    btnFindStudent.HorizontalAlignment = HorizontalAlignment.Right;
                    btnFindStudent.Height = 20;
                    btnFindStudent.Width = 36;

                    TextBlock textBlock = new TextBlock();
                    textBlock.Text = String.Format(node.Element("FirstName").Value + " " + (node.Element("LastName").Value));
                    textBlock.TextAlignment = TextAlignment.Center;

                    TextBlock textBlock1 = new TextBlock();
                    textBlock1.Text = (DateTime.Parse(node.Element("TimeAdded").Value)).ToString("d");
                    String.Format("{0:d/M/yyyy}", DateTime.Parse(node.Element("TimeAdded").Value));
                    textBlock1.TextAlignment = TextAlignment.Center;
                    textBlock1.VerticalAlignment = VerticalAlignment.Bottom;

                    StackPanel stackPanel = new StackPanel();
                    stackPanel.Children.Add(groupbox);
                    stackPanel.Children.Add(btnFindStudent);
                    stackPanel.Children.Add(textBlock);
                    stackPanel.Children.Add(textBlock1);
                    stackPanel.Margin = new Thickness(5);
                    stackPanel.MouseEnter += new MouseEventHandler(stackpanel_MouseEnter);
                    stackPanel.MouseLeave += new MouseEventHandler(stackpanel_MouseLeave);
                    MainArea1.Children.Add(stackPanel);
                }
            }

And the output looks like this:

enter image description here

Notice the GroupBox.header states the UserID.

So this brings me to the problem… if you notice in the image I also dynamically set a button (code above). This button loads a usercontrol applie named ThisUser 🙂 but the problem I am having is being able to:

1) First get GroupBox.Header(UserID) of the currently clicked
student (SOLVED by Darins answer below)

2) Send that UserID to the usercontrol “ThisUser”

To explain question 1):

Looking at the code above is there a way in which I can “Get” the groubox.header of that user who has been clicked (“view” button in the image of my app)

And for question 2)

Somehow “send” from my current app to the usercontrol “ThisUser” or “make available” for the usercontrol to then consume.

I hope this has been nice and clear and layed out well to provide the best possible answer, if there is anything else you wish to know (code, explanation) please dont hesitate to ask.

Code to send data on btnGeneralClick (view button):

    public FindStudent()
    {
        InitializeComponent();
    }
    private void btnGeneral_Click(object sender, RoutedEventArgs e)
    {

        ViewStudent myusercontrol = new ViewStudent();
        String id = (String)((Button)sender).Tag;
        myusercontrol.StudentID = id;
        PanelMainContent.Children.Add(myusercontrol);

    }

UserControl:

public partial class ViewStudent : UserControl
{

    public ViewStudent()
    {
        InitializeComponent();

    }
    private string _studentID;

    public string StudentID
    {
        get
        {
            return _studentID;
        }
        set
        {
            _studentID = value;
        }
    }
    protected override void OnInitialized(EventArgs e)
    {
        base.OnInitialized(e);
        groupBox1.Header = StudentID;
        //or
        textBlock1.Text = StudentID;
    }
}
  • 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-02T09:15:20+00:00Added an answer on June 2, 2026 at 9:15 am

    Well, first, I’d put the StudentID in the btnFindStudent.Tag

    btnFindStudent.Tag = node.Element("StudentID").Value.ToString();
    

    When the ClickEvent is fired, you can pull the ID out of the Tag and send it off to your ThisUser UserControl.

    String id = (String)((Button)sender).Tag;
    

    I’d just create a public property in the UserControl called “StudentID” and set it there. It’s hard to say without seeing your UserControl. 🙁

    More Information:

    Add this to ViewStudent:

    #region StudentID
    
    public static readonly DependencyProperty StudentIDProperty = DependencyProperty.Register("StudentID", typeof(String), typeof(ViewStudent), new PropertyMetadata(OnStudentIDChanged));
    
    public string StudentID
    {
        get { return (string)GetValue(StudentIDProperty); }
        set { SetValue(StudentIDProperty, value); }
    }
    
    static void OnStudentIDChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        (d as ViewStudent).OnStudentIDChanged(e);
    }
    
    void OnStudentIDChanged(DependencyPropertyChangedEventArgs e)
    {
        groupBox1.Header = StudentID;
        textBlock1.Text = StudentID;
    }
    
    #endregion
    

    And get rid of that other StudentID Property we made earlier.

    ViewStudent myUserControl = new ViewStudent();
    myUserControl.StudentID = (String)((Button)sender).Tag;
    

    Give that a shot. (:

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

Sidebar

Related Questions

This might sound a bit confusing at first. But I have a table with
This might sound like a strange question, but bear with me... I have a
This might sound like a reaaaally dumb question but... why do browsers have a
This might sound odd, but is there a 'Rails way' to have a model
This might sound like a noob question but this is the first time I'm
I know this might sound silly but I have no idea how to do
I know this question might sound strange because GLib is a portability library, but
This might sound strange (or even dangerous) but I would like to deploy one
This might sound kinda strange question but I am puzzled. I was just looking
This might sound stupid, but I'm seriously a newbie at Android programming. I have

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.