0

Is there a way to open a new window instance within the primary application window and still wait for a user response before continuing with the main program? I just have a 3 option query with a picture to be offered to the user and a whole new window opening up seems like overkill, I would much prefer it opening in a frame within the current window.

Do something like this sans the separate window:

 OptionWindow optionDialog = new OptionWindow();
 optionDialog.Owner = this;
 optionDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
 optionDialog.ShowDialog();
 if (optionDialog.DialogResult == true)
 {
    something;
 {
Erik S
  • 45
  • 6
  • What you're asking is unclear to me. Can you elaborate or post a screenshot? – Federico Berasategui Aug 05 '13 at 19:40
  • It sounds like you want a modal dialog. They block the program flow while open, it would be much quicker to implement than implementing some frame and having to block all input. – Robadob Aug 05 '13 at 19:41
  • 3
    It sounds like you are wanting to embed a Wpf Window in an existing Wpf Window, as far as I know that is not possible. You could try using an UserControl and disabling all of the other items until you are finished. – Mark Hall Aug 05 '13 at 19:43
  • Take a look at http://stackoverflow.com/questions/2477489/wpf-and-prism-view-overlay/2478498#2478498 – Pete Aug 05 '13 at 19:53

2 Answers2

1

Seems like you could just have your "OptionWindow" be a frame that is on the WPF form, and when you want to show it, just disable all other panels and show the frame with your dialog, and after the user completes the dialog, enable all other panels and hide your dialog frame.

After I posted my answer, I saw that Mark Hall made an edit to his comment with pretty much the same suggestion. Sorry Mark.

  • All of the information could be transferred from the Option window to the main program and placed in a frame, that is actually how I had it set up initially. But I don't know how to stop the other parts of the program from running until the user makes a selection. – Erik S Aug 05 '13 at 20:15
  • I'm not sure how complex your main program window is, but my thought would be to make all the other controls disabled, or change the visibility of the frames and make them hidden, and when they make a choice on the Option frame, enable and show the other controls again, and hide your frame. – seekerOfKnowledge Aug 05 '13 at 20:19
  • The dialog currently opens in a middle of an event. Would there be a way to pause the program so it does not continue to the later sections of the event until after a user input? The dialog box pauses processing of further commands in the main window until the dialog box is close. Is there a way to have a similar effect while using a frame instead of dialog? – Erik S Aug 05 '13 at 21:22
  • `private bool DialogComplete {get; set;} protected void Some_Event(object sender, EventArgs e) { /* Current event code before dialog show */ DialogComplete = false; ShowOptions(); /* Current event code after dialog show */ } protected void ShowOptions() { /* Show the dialog and hide everything else and stuff */ while(!DialogComplete) { } } protected void btnDialogFinish_Click(object sender, EventArgs e) { DialogComplete = true; }` – seekerOfKnowledge Aug 06 '13 at 09:31
  • It's a bit ugly, and you may need to start a new thread even. For purpose of crediting my inspiration, this is the question I got it from: http://stackoverflow.com/questions/15888608/wpf-c-sharp-button-wait-for-a-button-press – seekerOfKnowledge Aug 06 '13 at 09:36
0

I guess you are looking for modal window which can be achieved using Window.Showdialog.

Opens a window and returns only when the newly opened window is closed.

Rohit Vats
  • 79,502
  • 12
  • 161
  • 185