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

  • Home
  • SEARCH
  • 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 535961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:46:19+00:00 2026-05-13T09:46:19+00:00

I’m in a mess with visibility between classes. Please, help me with this newbie

  • 0

I’m in a mess with visibility between classes. Please, help me with this newbie question.

I have two controls (DatePickers from default WPF toolbox) which are in different windows, so in different classes. I can easily access these controls properties like datePicker1.Text from within its native class, i.e. in its native window, but when I try to reach datePicker1.Text from another window I get nothing.

I try to assign value of one datePicker to another, using reference to the window in my code:

string testStr;
...
AnotherWindow aw = new AnotherWindow();
testStr = aw.datePicker2.Text;
datePicker1.Text = testStr;

and it doesn’t work

also I tried to do it through public property of a class, like:

public partial class AnotherWindow : Window
{
....

public string dateNearest
    {

        get { return datePicker2.Text; }
        set { datePicker2.Text = value; }
    }
....

and then use it in another window:

string testStr;
...      
AnotherWindow aw = new AnotherWindow();
testStr = aw.dateNearest;

but also no value assigned.

Please, help me to understand this basic issue. I know there are other ways of accessing values in WPF like databinding, but I would like to understand basics first.

  • 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-13T09:46:19+00:00Added an answer on May 13, 2026 at 9:46 am

    I’m using VS 2010 beta 2 right now which crashes regularly doing the simplest WPF coding, like trying to duplicate your question’s code 🙂 : but consider :

    Is it possible that using this syntax will “do the right thing” :

        public string dateNearest 
        { 
            get { return this.datePicker2.Text; } 
            set { this.datePicker2.Text = value; } 
        }
    

    Edit 1 : Okay, I got a WPF replication of your code that didn’t crash : using the above syntax I can both get and set the property in the “other window.”

    Edit 2 : The code also works using your original code 🙂 Which, seemed to me to be “proper” the first time I read it. Are you setting that property before you read it ? : to my knowledge a DateTimePicker’s Text property will be an empty string by default when first created.

    Edit 3 : in response to Rem’s request :

    1. the main window has a button, ‘button1 : which tests setting and getting the Public Property DTContent defined in the instance of the second Window named : ‘WindowAdded : here’s the ‘Click event handler for that button in the main window’s code :

      private void button1_Click(object sender, RoutedEventArgs e)
      {
        WindowAdded wa = new WindowAdded();    
        wa.DTContent = DateTime.Now.ToString();
        Console.WriteLine("dt = " + wa.DTContent);
      }
      

    Edit 4 : a better “real world” example : most cases you are going to want to create that instance of another window, and hold on to it, for re-use: imho : not have it exist only within the scope of a button’s Click event. So consider, please :

    Somewhere in the scope of the main window’s code define a “place-holder” for the window(s) you will add : private WindowAdded wa;

    In the event you select as most appropriate for creating the instance of that window : create the instance, and assign to your “place-holder” variable : then re-use it as needed. In WinForms I most often create required secondary windows that I will need to re-use references to the instances of to access something on them in the main form’s load or shown events.

    Discussion : of course, if your intent is to create “temporary” windows, and you don’t need to re-use that reference to the new window’s instance again, then creating it in the scope of some function is fine.

    And, if the only thing you ever need to access on your second Window is the DateTimePicker, then you use the same technique suggested above, but create and hold to a reference to the instance of the DateTimePicker only.

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

Sidebar

Related Questions

No related questions found

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.