예제 #1
0
        /// <summary>
        /// Create a desktop notification to inform the user of important information.
        /// The passed through action will allow them to proceed with whatever you want them too.
        /// </summary>
        public void Toast(string message, string header = "ImprezGarage Alert", string buttonContent = null, Action action = null)
        {
            // Calculate the Id for this notification. It will either be zero or it will be one more than the Id of the last toast.
            var i = 0;

            if (_notificationsModel.Notifications.Any())
            {
                i = _notificationsModel.Notifications.Last().Id + 1;
            }

            var toast = new Toast();

            if (toast.DataContext is ToastViewModel viewModel)
            {
                viewModel.Id = i;
                viewModel.Header = header;
                viewModel.Message = message;
                viewModel.ButtonContent = buttonContent;
                viewModel.Action = action;
                toast.Closed += (s, a) =>
                {
                    _notificationsModel.LowerActivePopUps(viewModel.Id);
                };

                _notificationsModel.Notifications.Add(viewModel);
            }

            toast.Show();
            toast.BringIntoView();
        }