public void showAlert(string message, AlertBox.MessageType type = AlertBox.MessageType.Success) { AlertBox alertBox = new AlertBox(); DispatcherTimer alertTimeout = new DispatcherTimer(); alertBox.SetMessage(message, type); alertTimeout.Interval = TimeSpan.FromSeconds(5); alertTimeout.Tick += delegate { alertTimeout.Stop(); AlertStack.Children.Remove(alertBox); alertBox = null; alertTimeout = null; }; alertBox.MouseUp += delegate { alertTimeout.Stop(); AlertStack.Children.Remove(alertBox); alertBox = null; alertTimeout = null; }; AlertStack.Children.Add(alertBox); alertTimeout.Start(); }