I am using VS 2010 beta 2 right now, which leads to crashes regularly performing the simplest WPF encoding, for example, trying to duplicate your question code :): but note:
Is it possible that using this syntax will "go right":
public string dateNearest { get { return this.datePicker2.Text; } set { this.datePicker2.Text = value; } }
Edit 1: Well, I got a WPF replica of your code that didn't work: using the syntax above, I can both get and set the property in a “different window”.
Edit 2: The code also works using your source code :) Which seemed to be “correct” the first time I read it. Do you set this property before reading it ?: As far as I know, the DateTimePicker Text property will be the default empty string on first creation.
Edit 3: in response to Rem request:
In the main window there is a button "button1: which sets the parameters and gets the value of the open DTContent property defined in the second window instance with the name:" WindowAdded: here "" Click event handler for this button in the main window window 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: the best example of the “real world”: in most cases you will want to create this instance of another window and hold it for reuse: imho: do not have it only within the scope of the Click event button. Therefore, please consider:
Somewhere within the main code window, define a "place holder" for the window (s) you add: private WindowAdded wa;
If you select the most suitable for creating an instance of this window: create an instance and assign the variable "place-holder": then reuse it as necessary. In WinForms, I most often create the required secondary windows, which I will need to reuse instance references to access any of them in the main form load or displayed events.
Discussion: of course, if you intend to create "temporary" windows, and you do not need to use this link again for a new instance of the window, and then create it as part of a function.
And if the only thing you ever need to access your second window is DateTimePicker, then you use the same method as suggested above, but create and hold only a reference to the DateTimePicker instance.