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

The Archive Base Latest Questions

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

I have a issue with passing information from one wpf window to another. For

  • 0

I have a issue with passing information from one wpf window to another. For some reason when main window is loaded nothing is set in the label, I need to be able to keep the data in a string to use for anything (label not important but shows what I mean)?

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
    public string MyData { get; set; }

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        label1.Content = MyData;

    }

public partial class LoginWindow : Window
{
    public LoginWindow()
    {
        InitializeComponent();
    }
    private void button2_Click(object sender, RoutedEventArgs e)
    {
         string mytext = "blabla";
         MainWindow fromloginwindow = new MainWindow(); 
         fromloginwindow.Mydata = mytext;
    }

Or am I doing this the wrong way round?

EDIT:

Please do not go on a tangent about the label its unimportant I need to be able to get and set a string for use anywhere in the MainWindow. Also the string “mytext” is also irrelevant as obviously I will not be setting the string this way.

  • 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-02T14:40:24+00:00Added an answer on June 2, 2026 at 2:40 pm

    It sounds like you are running into an event lifecycle issue; the calls to the Loaded event happen pretty quickly and thus, the chance to set the text has passed. Instead, what you should do is either:

    1) Bind the Property to the Label in the XAML

    public event PropertyChangedEventHandler PropertyChanged;
    
    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
    }
    
    protected string _myData = string.Empty;
    public string MyData
    {
        get { return _myData; }
        set { _myData = value; NotifyPropertyChanged("MyData"); }
    }
    
    protected void NotifyPropertyChanged(string propName)
    {
        var methods = PropertyChanged;
    
        if(methods != null)
           methods(this, new PropertyChangedEventArgs(propName));
    }
    
    <Label Content="{Binding MyData}" />
    

    2) Set the control text via another method (or inside the property declaration):

    public void SetLabel(string text)
    {
        label1.Content = text;
    }
    
    protected void button2_Click(object sender, RoutedEventArgs e)
    {
         MainWindow x = new MainWindow();
         x.SetLabel("blabla");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue with the submitted form information. Decimal parsing fails when I
I have an issue. One of my JS scripts needs Facebook SDK and Twitter
I have one issue with retrieval Parent/Child relationship of type Folder Hierarchy Ideally, in
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
We are new to ROR, We have issue in creating Login/Logout process in ROR
Share your ideas please! I have issue to check the folder and convert a
I have an issue with an open source C++ project that I have been
I have an issue when playing video while using the c willRotateToInterfaceOrientation function. Initially,
I have an issue with a toggling animation with JQuery. I have a menu,
I have an issue when the grid's Add functionality kicks in. My colModel defines

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.