It would be nice to have a generic Result parameter apart from the classic true / false result.
a quick thought is below.
public interface IDialogResult<T> : IDialogResult where T:class
{
T Entity { get;set; }
}
and also it would be nice if you can make Result and IDialogParameters properties as protected so that if someone wants to create an extended version of IDialogResult then they can set those parameters from the constructor.
public class CustomerInfoResult : DialogResult, IDialogResult<string>
{
public CustomerInfoResult(IDialogResult result)
{
//this is not possible at the moment
Parameters = result.Parameters;
Result = result.Result;
}
public string Entity { get; set; }
}
so I made it this way
public class CustomerInfoResult : IDialogResult<string>
{
public CustomerInfoResult(IDialogResult result)
{
Parameters = result.Parameters;
Result = result.Result;
}
public string Entity { get; set; }
public IDialogParameters Parameters { get; }
public bool? Result { get; }
}
private void ExecuteShowDialog()
{
var message = "This is a message that should be shown in the dialog.";
//using the dialog service as-is
_dialogService.ShowDialog("NotificationDialog", new DialogParameters($"message={message}"), r =>
{
var customerResult = r as CustomerInfoResult;
if (!r.Result.HasValue)
Title = "Result is null";
else if (r.Result == true)
{
if (customerResult != null)
{
Title = $"Result is True";
Entity = customerResult.Entity;
}
}
else if (r.Result == false)
Title = "Result is False";
else
Title = "What the hell did you do?";
});
}
Thanks in advance.
How would you propose modifying the UI to set the T of the DialogResult?
Also, this isn't really necessary because you can get your strongly type object from the parameters list
var person = r.Prameters<Person>("person");
Thanks for your quick reply as usual. You mean to pass back the Person entity in DialogParameter ?
Yes, that's what the parameters are for. You can pass back multiple values without having to create a class to wrap everything.
Also, you would need to modify the API to allow the developer to set the T for the result. So it might have to look something like
ShowDialog<Person>("DialogName", parameters, r =>
{
var person = r.Entity.
});
This is not really a friendly API and really limits you to a single return parameter.
Thanks @brianlagunas. I will follow your advice. You had a profound influence turning me in to a better developer.
Thanks a lot
How would you propose modifying the UI to set the
Tof the DialogResult?Also, this isn't really necessary because you can get your strongly type object from the parameters list
var person = r.Prameters<Person>("person");
Hey @brianlagunas! How exactly can I return (for example) entity framework context or some generic collection through DialogResult (it expects string).
It's not possible, right? am I missing something or should I be doing it some other way.
@wire-issues I think you should try the API first. It will become clear when you do.
I did couple of days ago, before posting, couldn't figure it out.
My mistake (i was doing this):
RaiseRequestClose(new DialogResult(true, new DialogParameters($"person={selectedPerson}")));
SelectedPerson = r.Parameters.GetValue<Person>("person");
System.InvalidCastException: 'Invalid cast from 'System.String' to 'Person`
Should've checked the implementation, lesson learned. :face_with_head_bandage:
IDialogParameters accepts value as object.
dialogParameters.Add("person", selectedPerson);
Thanks!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
How would you propose modifying the UI to set the
Tof the DialogResult?Also, this isn't really necessary because you can get your strongly type object from the parameters list