0

I want show my app user with a MessageBox based on some activity happened in that class. I was just wondering what could be the best way to do so. One way that I know doesn't seem to be the ideal one.

Deployment.Current.Dispatcher.BeginInvoke(() =>
{
    MessageBox.Show(MessageString, TitleString, MessageBoxButton.OK);
});
pratpor
  • 1,954
  • 1
  • 27
  • 46
  • What about IoC (Dependency Injection)? You can prepare `INotificationService` that shares method `NotifyUser(string msg, string title)` (and other overloads), implement it (with your code) and pass instance via construtor to any class that you want to? –  Jul 30 '14 at 07:49
  • `MessageBox` is not ideal mechanism to notify user about something. You should use some other kind that does not require user to click a button for each message to be received. Maybe some status line that can be expanded to several lines. – Dialecticus Jul 30 '14 at 08:13
  • @Dialecticus It doesn't happen on user click. I have some other code logic to decide in that class based on which I want to trigger this. – pratpor Jul 30 '14 at 08:17
  • @pwas I am new to this. Can you please suggest some link or tutorial for getting started with this IoC. I tried goggling it, but didn't land up on a helpful link. thanks – pratpor Jul 30 '14 at 11:52

1 Answers1

0

You could try a toast notification

ShellToast toast = new ShellToast();
toast.Title = "[title]";
toast.Content = "[content]";
toast.Show();
Clinton Ward
  • 2,441
  • 1
  • 22
  • 26
  • You can't use a ShellToast while the app is the foreground app. It's meant to be invoked from a background service while the app isn't the foreground app. – pratpor Jul 30 '14 at 08:25
  • On devices with Windows Phone 8 Update 3, toast notifications are displayed when the target app is running in the foreground but is obscured by other activity such as a phone call or the lock screen. – Clinton Ward Jul 30 '14 at 08:27