简体   繁体   中英

How to Create an “Apply” Button on a Modal Dialog Window

I have a vb.net WPF application that has a modal dialog window that has an "Ok", "Cancel" and "Apply" button. The "Apply" button does the same work as the "Ok" button but when the "Apply" is clicked the modal dialog box should stay open. Normally I like to call ShowDialog to display a modal but that results in the modal closing when it returns so I can't use that with a modal the has an "Apply" button. Can someone provide me with an easy work around? The alternative is to display the modal dialog window using .Show but in this case I'm not sure how to properly return values when the user clicks on one of the buttons.

Thanks!

The closing of the dialog is handled by the code that executes when the user clicks the OK button. So you could move all of that code to a function with the exception of the Close() call and the call that sets the DialogResult. Then you can call that function from both the OK handler (or ICommand) and the Apply handler (or ICommand). Then just don't call Close() from the Apply button.

Dialogs with an "Apply" button aren't generally modal, but one approach would be to instantiate your dialog and supply it with a ViewModel via DataContext where your dialog data can be shared between the function calling the dialog and and the dialog itself. Then, wire your "Apply" button to be handled by the modal dialog and whatever ViewModel code you have, perhaps via an ICommand binding.

Let us know if a sample would be useful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM