1

I have a ViewModel defined like

public class PlayerViewModel : Screen, IDiscoverableViewModel

I am showing a dialog pop up as

var result = await _dialogManager.ShowDialogAsync(item, new List<DialogResult>() { DialogResult.Cancel });

Here item is the another ViewModel which shows UI from the related View. This pop up is showing some information and needs to be auto closed after few seconds in case user doesn't select Cancel button.

Following is the Timer tick event that is getting fired after 10 seconds.

void timer_Tick(object sender, EventArgs e)
{
    this.DialogHost().TryClose(DialogResult.Cancel);
}

But it's not working and throwing exception as this.DialoHost() is getting null always. I tried this solution but it is closing the whole ViewModel instead I want to close only the dialog window.

Ajendra Prasad
  • 299
  • 1
  • 8
  • 22

1 Answers1

1

Could you confirm if your 'pop-up viewmodel' is deriving from Screen ? If so, TryClose should work. Could you please verify it ? Sample code for closing.

public class CreatePersonViewModel:Screen
{

    System.Timers.Timer _timer = new Timer(5000);
    public CreatePersonViewModel()
    {

        _timer.Elapsed += (sender, args) =>
        {
            _timer.Enabled = false;
            TryClose(true);
        };
        _timer.Start();
    }
}
Anu Viswan
  • 17,797
  • 2
  • 22
  • 51
  • Hi @Anu, yes it makes sense. Though I have derived the pop up viewmodel from Screen but what I was missing is using timer inside the pop up viewmodel instead of the parent viewmodel. After moving timer tick to the pop up viewmodel, it worked. Thanks. – Ajendra Prasad Jul 30 '18 at 08:36