How do I validate a user prompt that is displayed with a gray overlay

WPF Studio, Themes, and Shared Library for WPF Forum

The latest build of this product (v25.1.0) was released 2 months ago, which was before this thread was created.
Posted 23 days ago by Pascal
Version: 25.1.0
Avatar

Hello,

I am currently building a form that is displayed through a user prompt with overlay. I am using the UserPromptBuilder pattern.

I would like to validate the content of the form, when the user clicks on OK. If validation fails, I'd like to show an error in red in the form. How do I do this?

Right now, I simply get the dialog's result and if there is an error, I show a message box with the error message. If I could display the error directly in my control, it would be great.

I tried using OnReponding but it didn't work.

Thanks,

Pascal

Comments (2)

Posted 23 days ago by Pascal
Avatar

OK i found a work around. It's stupid but it works.

After I show the prompt, I get the result.

If it's ok, then I validate with a method on my form object. If validation pass, I continue. If it doesn't... it's a while loop and display the form a 2nd time. Since my validation method also changes the field to red, it makes what I want. So it works.

However, I was wondering if there was a more elegant way to make validations in a user prompt.

No need to work on a feature for this, my work-around works.

Thanks

Pascal

Posted 22 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

I'm glad you found a working solution, although I think the ideal scenario would be to prevent the form from closing at all.  The OnResponding callback should be what you need since you're trying to cancel the prompt from closing.  Have you looked at the "Programmatically cancel the response" sample in our Sample Browser application?  The following example code from that sample shows the basic process of preventing the prompt from closing if a checkbox is checked:

var result = await UserPromptBuilder.Configure()
  // Other common settings here
  .OnResponding((builder, args) => {
    // This event handler must be executed synchronously so
    // the sender will be blocked waiting for the response
    if (builder?.Instance is UserPromptControl userPromptControl) {
	
      // This example cancels when the prompt is checked
      if (userPromptControl.IsChecked)
        e.Cancel = true;
    }
  })
  .Show();

You should be able to perform your validation logic in the same routine and set "e.Cancel = true" if the validation fails.  If this callback wasn't working for you, we'd like to help figure out why and see if there is anything we need to address.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.