I have spent two day trying to figure it out.
I have implemented two ways of working with mvvm popup windows
Example of the first aproach usage:
_childWindowController
.ShowDialogWithResult<AddNationalityPopup,AddNationalityPopupModel, AddNationalityResult>(
(result, a) =>
{
if (a.DialogResult.HasValue && a.DialogResult.Value)
{
if (result.NationalityCountryId.HasValue)
{
Background.NationalityCountryId = result.NationalityCountryId.Value;
Background.NationalityDescription = result.NationalityDescription;
}
}
});
The second approach:
var window = _childWindowController.CreateDialog<AddNationalityPopup>();
window.Closed += (sender, args) =>
{
if (args.DialogResult.HasValue && args.DialogResult.Value)
{
var result = (AddNationalityResult)window.Result;
if (result.NationalityCountryId.HasValue)
{
Background.NationalityCountryId = result.NationalityCountryId.Value;
Background.NationalityDescription = result.NationalityDescription;
}
}
};
window.ShowDialog();
In the first approach user of the service should know the types of view , view model, and result to be able to show dialog
In the second one interface is simplified a bit, but I still had to know to what type cast the result before its usage.
Have you ever faced the problem of showing dialog with view model?
How to improve the design of the window service?
Can you give an example of good implementation of the dialog service?