简体   繁体   English

如何在模态对话框窗口上创建“应用”按钮

[英]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. 我有一个vb.net WPF应用程序,它有一个模式对话框窗口,其中包含“确定”,“取消”和“应用”按钮。 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. 通常我喜欢调用ShowDialog来显示一个模态,但是当它返回时会导致模态关闭,所以我不能在模态中使用它有一个“应用”按钮。 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. 另一种方法是使用.Show显示模式对话框窗口,但在这种情况下,当用户单击其中一个按钮时,我不确定如何正确返回值。

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. 因此,您可以将所有代码移动到一个函数,但Close()调用和设置DialogResult的调用除外。 Then you can call that function from both the OK handler (or ICommand) and the Apply handler (or ICommand). 然后,您可以从OK处理程序(或ICommand)和Apply处理程序(或ICommand)中调用该函数。 Then just don't call Close() from the Apply button. 然后只是不要从Apply按钮调用Close()。

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. 带有“Apply”按钮的对话框通常不是模态的,但一种方法是实例化对话框并通过DataContext为ViewModel提供对话框数据,其中对话框数据可以在调用对话框的函数和对话框本身之间共享。 Then, wire your "Apply" button to be handled by the modal dialog and whatever ViewModel code you have, perhaps via an ICommand binding. 然后,连接您的“应用”按钮,由模式对话框和您拥有的任何ViewModel代码处理,可能通过ICommand绑定。

Let us know if a sample would be useful. 如果样本有用,请告诉我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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