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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:08:38+00:00 2026-06-03T01:08:38+00:00

I get an error trying to send a string from one window to another

  • 0

I get an error trying to send a string from one window to another in my wpf application:

Unable to cast object of type ‘WpfApplication4.LoginWindow’ to type ‘WpfApplication4.MainWindow’.

In my login window the error is on this line:

((MainWindow)Application.Current.MainWindow).StudentID = UserAuthenticationID;

In my main window I have this to test:

    public string StudentId { get; set; }
    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        label1.Content = StudentID;
    }

What am I doing wrong?

EDIT:

No answer has made sense so far, which will be due to my obscure question, I created a wpf application and I have two windows MainWindow.xaml and LoginWindow.xaml.

I want to pass a string (student id) from the login window to the main window after authentication.

I thought the above method was how to do it, as I read it: ((MainWindow)Application.Current.MainWindow).StudentID says where I am intending the string UserAuthenticationID to be sent to?

Then in the MainWindow.xaml I get the string UserAuthenticationID and set it, I then assign a labels content to this public string?

  • 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-03T01:08:39+00:00Added an answer on June 3, 2026 at 1:08 am

    Presumably you create your login window from your main window. If you need to reference your main window from your login window then pass a main window reference to your login window when you construct it. Eg

    void MainWindow_Loaded(object sender, RoutedEventArgs e) {
        LoginWindow login = new LoginWindow(this);
        login.ShowDialog();
    }
    
    class LoginWindow : Window {
        MainWindow app_window;
        public LoginWindow(MainWindow app_window) {
            Owner = app_window;
            this->app_window = app_window;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get one side to send an error message to client, but
I am trying to pull in a string from one activity to another but
I get this error when trying to load a Zend Framework application: Fatal error:
I get following error when trying to access Xampp from a network I've tried
I get the following error when trying to run my application. There are no
I get the following error when trying to push changes to github from the
I am trying to send an image from a Java desktop application to a
I am trying to send audio file from one computer to other using socket
I am trying to send JSON data from a form using the XMLHttpRequest object.
I'm trying to get the contents from another file with file_get_contents (don't ask why).

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.