Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/Wpf.Ui/Controls/Snackbar/SnackbarPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,35 @@ public SnackbarPresenter()

protected virtual void OnUnloaded()
{
if (CancellationTokenSource.IsCancellationRequested)
{
return;
}

ImmediatelyHideCurrent();
ResetCancellationTokenSource();
}

private void ImmediatelyHideCurrent()
{
if (Content is null)
{
return;
}

CancellationTokenSource.Cancel();
CancellationTokenSource.Dispose();
ImmediatelyHidSnackbar(Content);
}

[System.Diagnostics.CodeAnalysis.SuppressMessage(
"WpfAnalyzers.DependencyProperty",
"WPF0041:Set mutable dependency properties using SetCurrentValue",
Justification = "SetCurrentValue(ContentProperty, ...) will not work"
)]
private void ImmediatelyHidSnackbar(Snackbar snackbar)
{
snackbar.SetCurrentValue(Snackbar.IsShownProperty, false);
Content = null;
}

protected void ResetCancellationTokenSource()
Expand Down Expand Up @@ -120,4 +147,14 @@ private async Task HidSnackbar(Snackbar snackbar)

Content = null;
}

~SnackbarPresenter()
{
if (!CancellationTokenSource.IsCancellationRequested)
{
CancellationTokenSource.Cancel();
}

CancellationTokenSource.Dispose();
}
}