Skip to content

Toast/Notification global Trigger #603

@nadirvishun

Description

@nadirvishun

In the example, there is a strong dependency on the view layer TopLevel.GetTopLevel(this) to ensure that the popup appears on top.

protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
var topLevel = TopLevel.GetTopLevel(this);
_viewModel.ToastManager = new WindowToastManager(topLevel) { MaxItems = 3 };
}
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
_viewModel.ToastManager?.Uninstall();
}
}

However, I am currently using HttpClient to request API interfaces. When the API interface returns an error, I want to globally toast a prompt (not in ViewModels, but in a common method encapsulated in a separate class DelegatingHandler). What should I do in this case?
At present, the only method I can think of is to use WeakReferenceMessenger for message passing, but is there a more convenient method?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions