c# - automatic open new window without timer WPF -
I need help with some problems. In the main window WPF reads the position from the device and 0 is normal work, 1 The other situation is When I get the position = 1, I want to open a new window and when I get 0, I close it. I try to do it with a timer and showdial. A new window has been created but the status does not change in the main window until I close the new window manual. How to do this without any timer? Maybe some sample.
Thank you in advance.
Main Window - Timer Tick:
Public Zero T1_Tick (Object Sender, EventArgs E) {HttpWebRequest request7 = WebRequest.Create ("http: // LocalHost: 8080 / HttpWebRequest as DataTap / Rest / Teatomater Server / UCard "); (HttpWebResponse response7 = HttpWebResponse as request7.GetResponse ()) {StreamReader Reader 7 = Using new streamreader (response7.GetResponsestream ()); String json7 = reader7.ReadToEnd (); // message box. Show (JSN); Jobbject o7 = Jobbject.Parse (json7); Int Statement = Convert. ToInt32 (o7 ["Result"] [0]); If (status_int == 1) {uCard uc1 = new Euclide (); Uc1.ShowDialog (); }}
Window 1 - close window
public zero t1_Tick (object sender, EventArgs e) {if (MainWindow.status_int == 0) { this. Close (); }}
First of all, to create an event for you to raise when the price changes Required:
Public Event Action & lt; Int & gt; StatusChanged;
And to change it when a property changes:
// It is very close to a standard INotifyPropertyChanged Private int status_int = 0; PrivateInstate Status {Return Statement; } Set {if (status! = Value) {status_int = value; StatusChanged (value); }}}
Get rid of the status check in your timer, just set the variable:
position = recover_states;
Register for this event:
Public Manvando () {StatusChanged + = HandleStatusChange; }
and to pass your "ShowDialog" to the real example of the form:
Change Private Zero handles (int NewView) {If (newValue == 1) {// is threaded, then we do not hang timer callback new thread ((=) (uCard uc1 = new eCard (this); uc1.ShowDialog ();}) We do. (); }}
Then in your popup, your constructor will be:
public ukard (menu-window) {window.StatusChanged + = CheckForClose; }
You will be able to get rid of that timer and:
Private Zero CheckForclosus (Int NewValue) {if (newValue == 0) {this. Close (); }}
Its still very bad, but very cleaner and more importantly, it will really work.
Comments
Post a Comment