0

I have a question about accessing dialogdata from wpf/ I have a ProgressDialog :System.Windows.Window And I am calling it in OnButtonClick like this:

        void OnButtonClick(object sender, RoutedEventArgs e)
        {   
            ProgressDialog dlg = new ProgressDialog("");
            //dlg.AutoIncrementInterval = 0;
            LibWrap lwrap = new LibWrap();
            DoWorkEventHandler handler = delegate { BitmapFrame bf = lwrap.engine(frame); };
            dlg.CurrentLibWrap = lwrap;
            dlg.AutoIncrementInterval = 100;
            dlg.IsCancellingEnabled = true;
            dlg.Owner = Application.Current.MainWindow;
            dlg.RunWorkerThread(0, handler);
}

The question is - how to check in this function(OnButtonClick) if the DialogResult is OK (in other words - how to access dlg's inner fields after it finish execution)?

H.B.
  • 166,899
  • 29
  • 327
  • 400
Papa John
  • 3,764
  • 3
  • 26
  • 23

1 Answers1

1

DialogResult usually is no inner field but a rather public property, so dlg.DialogResult should be fine (given that it inherits from Window), you will need to cast it to a bool.

I do not see you open the window anywhere, if you use ShowDialog the return value is automatically the DialogResult and the calling thread blocks until it gets closed.

var result = (bool)dlg.ShowDialog();

If you need a non-modal dialog you can use Show subscribe to the Closed event and check the DialogResult there.

dlg.Closed += (_,__) =>
{
    var result = (bool)dlg.ShowDialog();
    // Do something with it.
}
dlg.Show();

Of course the dialog needs to set the property in either case. Default actions like Alt+f4 set it to false.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • ShowDialog is in RunWorkerThread ->return ShowDialog() ?? false; – Papa John Dec 13 '11 at 16:14
  • it returns bool but I tried: if(dlg.RunWorkerThread(0, handler)) But my data was still in process - and i couldnot get an access – Papa John Dec 13 '11 at 16:16
  • Why would you do any kind of test? Just wait for the dialog to raise an event instead. – H.B. Dec 13 '11 at 16:22
  • I have tried dlg.Closing += new CancelEventHandler(dlg_Closing); dlg.Closed +=new EventHandler(dlg_Closed); Non of function dlg_Closed or dlg_Closing was hited after progress dialog was collapsed (not by error) ( – Papa John Dec 13 '11 at 16:29
  • collapsed or actually closed? Also if the dialog was actually closed the method *should* be called, i have no idea what you are doing there... – H.B. Dec 13 '11 at 16:30
  • closed. This is strange but that is. May be I must try to pass this events myself. – Papa John Dec 13 '11 at 16:36
  • I have found bug. I have subscribes on this events AFTER the dialog has to close(( when I moved dlg.Closing += new CancelEventHandler(dlg_Closing); right after ProgressDialog dlg = new ProgressDialog(""); all seems to be working... Thank you for your answers – Papa John Dec 13 '11 at 16:45