punker76 / MahApps.Metro.SimpleChildWindow

A simple child window for MahApps.Metro
MIT License
374 stars 55 forks source link

Get Result from "ShowChildWindowAsync" #85

Closed AndreasReitberger closed 5 years ago

AndreasReitberger commented 5 years ago

Hi, it's more a question like a bug.

When I use var result = _parent.ShowMessageAsync(...) I get a result if the dialog was confirmed or declined. How do I achive the same with the "ShowChildWindowsAsync(...)"?

var result = await _parent.ShowChildWindowAsync(...);

How do I return a "MessageResult" when my ChildWindow is closed? I couldn't find a sample.

Thanks a lot!

gem81 commented 5 years ago

you should use var result = await this.ShowChildWindowAsync<TResult>(...)); where TResult is type of result object

public class Person
{
    public string FirstName {get; set; }
}

var result = await this.ShowChildWindowAsync<Person>(...));

in your ChildWindow on Close event you should do something like

        private void Button1_OnClick(object sender, RoutedEventArgs e)
        {
            var PersonTypeObject = new Person() {FirstName = "John"};
            this.Close(PersonTypeObject);
        }
punker76 commented 5 years ago

@AndreasReitberger Was @gem81 able to help you with the code snippet?

AndreasReitberger commented 5 years ago

@punker76 Yes, this works for me :)

@gem81 thank you for helping out!

nagababuthota984 commented 2 years ago

you should use var result = await this.ShowChildWindowAsync<TResult>(...));where TResult is type of result object

public class Person
{
  public string FirstName {get; set; }
}

var result = await this.ShowChildWindowAsync<Person>(...));

in your ChildWindow on Close event you should do something like

      private void Button1_OnClick(object sender, RoutedEventArgs e)
      {
          var PersonTypeObject = new Person() {FirstName = "John"};
          this.Close(PersonTypeObject);
      }

@gem81 thanks for the code snippet. but how can we proceed in MVVM style with Caliburn.micro? I am thinking of using Events with event aggregator. is there any more efficient way?