Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Support for CancellationToken to cancel dialogs #2022

Merged
merged 1 commit into from
Jul 8, 2015

Conversation

thoemmi
Copy link
Collaborator

@thoemmi thoemmi commented Jul 5, 2015

As a possible solution for #2018 I implemented support for CancellationToken to cancel dialogs.

I added a CancellationToken to MetroDialogSettings and the handling of that token to InputDialog, LoginDialog, MessageDialog, and ProgressDialog. ProgressDialog's implementation is different from the others in that it only sets ProgressDialogManager.IsCanceled to true.

Of course, users of MahApps.Metro deriving their dialogs from BaseMetroDialog have to implement their own handling of the cancellation.

Usage

var cancellationTokenSource = new CancellationTokenSource();

var mySettings = new MetroDialogSettings()
{
    // ...
    CancellationToken = cancellationTokenSource.Token
};

Here's an example using a timer to cancel the message box (by calling cancellationTokenSource.Cancel()) after 10 seconds:

DispatcherTimer timer = null;
timer = new DispatcherTimer(
    TimeSpan.FromSeconds(10),
    DispatcherPriority.DataBind,
    (o, args) => {
        timer.Stop();
        cancellationTokenSource.Cancel();
    },
    Dispatcher
    );
timer.Start();

MessageDialogResult result = await this.ShowMessageAsync("Hello", "Welcome to metro!",
    MessageDialogStyle.AffirmativeAndNegative, mySettings);

@punker76 punker76 mentioned this pull request Jul 6, 2015
@punker76
Copy link
Member

punker76 commented Jul 7, 2015

@thoemmi It's a nice solution, but I'm torn about this because it's a breaking change...

@thoemmi
Copy link
Collaborator Author

thoemmi commented Jul 8, 2015

Why is it a breaking change? I added MetroDialogSettings.CancellationToken, but didn't change the existing functionality.

@punker76
Copy link
Member

punker76 commented Jul 8, 2015

@thoemmi :-( my mistake, it's all fine with this.

@punker76 punker76 added this to the 1.2.0 milestone Jul 8, 2015
punker76 added a commit that referenced this pull request Jul 8, 2015
[RFC] Support for CancellationToken to cancel dialogs
@punker76 punker76 merged commit 24413f7 into MahApps:master Jul 8, 2015
@thoemmi thoemmi deleted the cancelable-dialogs branch July 8, 2015 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants