✅ In WPF using a custom dialog service, how would i "validate" the dialog data before closing it?
I have a
NewUserWindow
, whose data context is a NewUserViewModel
and then i have a dialog service that is responsible for creating users (Task<string> CreateUserAsync(string defaultUsername = null)
) being the new user's name (or null if they clicked "Cancel"). But when the user clicks "OK" to create the user, i want to ensure the user doesn't already exist before the dialog closes (if the user exists, don't close the dialog).
Is there a good way to do this, without passing a list of existing users to my dialog service (which would look like Task<string> CreateUserAsync(ObservableCollection<string> existingUsers, string defaultUsername = null)
)?3 Replies
Do you have any uniqueness constraints in your backing data store? I.e. if you use SQL, do you have an index that ensures one cannot reuse the same username?
If so, you could rely on a duplicate key exception and catch it to stop the dialog from closing if the user already exists?
That was kinda just an example, i was trying to achieve a way to "validate" the state of the dialog's data context before closing it
but in order to validate it, it requires access to 1 or more other view models, in the example case
UserManagerViewModel
which contains that observable collection of existing users
This is what i have atm:
just not really sure if this is a good way of doing it, because i have to pass the existing users to the dialog serviceWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.