Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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 :</p> <p>Is it possible that using this syntax will "do the right thing" :</p> <pre><code> public string dateNearest { get { return this.datePicker2.Text; } set { this.datePicker2.Text = value; } } </code></pre> <p>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."</p> <p>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.</p> <p>Edit 3 : in response to Rem's request :</p> <ol> <li><p>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 :</p> <pre><code>private void button1_Click(object sender, RoutedEventArgs e) { WindowAdded wa = new WindowAdded(); wa.DTContent = DateTime.Now.ToString(); Console.WriteLine("dt = " + wa.DTContent); } </code></pre></li> </ol> <p>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 : <em>not</em> have it exist only within the scope of a button's Click event. So consider, please : </p> <p>Somewhere in the scope of the main window's code define a "place-holder" for the window(s) you will add : private WindowAdded wa;</p> <p>In the event <em>you select as most appropriate for creating the instance of that window</em> : 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.</p> <p>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.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload