mardi 22 septembre 2015

Windows Store Content Dialog Close programmaticaly

Close content Dialog programmaticaly Windows Universal app

The following code can be used to close the new content Dialog after a period of time.

private IAsyncOperation<ContentDialogResult> dialogTask;
    private void Button_Click(object sender, RoutedEventArgs e)
       ContentDialog dlg= new ContentDialog();
        dlg.Content = new TextBlock() { Text = "This content dialog will closed in 5sec!" };
            dialogTask = dlg.ShowAsync();
        catch (TaskCanceledException)
            //this was cancelled

        DispatcherTimer dt = new DispatcherTimer();
        dt.Interval = TimeSpan.FromSeconds(5);
        dt.Tick += dt_Tick;

    void dt_Tick(object sender, object e)
        (sender as DispatcherTimer).Stop();