How can I create a shelltoast? - c#

In my application I want to notify the user with the ShellToast.
Just by running...
var toast = new ShellToast
{
Title = "Nom nom nom!",
Content = "More! More! Keep feeding me!",
};
toast.Show();
...makes nothing happen, and as I understand it needs to be run from a ScheduledTaskAgent. But how do I run this on command, and make sure it only run once?

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.
If you want to have a UX similar to that of ShellToast use the Coding4fun toolkit ToastPrompt control. Here's a code snippet showing how to use it:
private void ToastWrapWithImgAndTitleClick(object sender, RoutedEventArgs e)
{
var toast = GetToastWithImgAndTitle();
toast.TextWrapping = TextWrapping.Wrap;
toast.Show();
}
private static ToastPrompt GetToastWithImgAndTitle()
{
return new ToastPrompt
{
Title = "With Image",
TextOrientation = System.Windows.Controls.Orientation.Vertical,
Message = LongText,
ImageSource = new BitmapImage(new Uri("../../ApplicationIcon.png", UriKind.RelativeOrAbsolute))
};
}
Running this code snippet shows the following:

Just a small update: using ShellToast when the app is in foreground, is now possible, when using Windows Phone 8 Update 3. Though, they are obscured by other activity such as a phone call or the lock screen. Source

Related

How to play shoutcast radio in C# UWP application?

I have UWP(Universal Windows Platform) Application and I want to add shoutcast player, but can't find anything how to do that.
I have Button which should start/stop playing music and volume slider.
I found element in xaml such as MediaElement but when I'm trying to use it like that:
private async void StartPlayer()
{
var result = await AdaptiveMediaSource.CreateFromUriAsync(new Uri("http://camon22.sxcore.net:"+Port, UriKind.Absolute));
if (result.Status == AdaptiveMediaSourceCreationStatus.Success)
{
var astream = result.MediaSource;
Media.SetMediaStreamSource(astream);
}
else
{
var dialog = new MessageDialog("Result Status Wrong!\n"+result.Status);
await dialog.ShowAsync();
}
}
I got UnsupportedManifestContestType Status.
Anybody knows how to play radio in UWP application?

Speech Recognition in UWP not works in background

I would like if Speech Recognition in UWP would recognize even if application is not active.
I have these settings currently:
async void InitializeSpeechRecognizer()
{
SpeechRecognizer speechRecognizer = new SpeechRecognizer();
speechRecognizer.StateChanged += HandleSpeech_State;
speechRecognizer.ContinuousRecognitionSession.ResultGenerated += HandleSpeech;
StorageFile grammar = await Package.Current.InstalledLocation.GetFileAsync(#"Grammar.xml"); // file
SpeechRecognitionGrammarFileConstraint grammarContraint = new SpeechRecognitionGrammarFileConstraint(grammar);
speechRecognizer.Constraints.Add(grammarContraint);
SpeechRecognitionCompilationResult compilantResult = await speechRecognizer.CompileConstraintsAsync(); // compile grammar
if (compilantResult.Status == SpeechRecognitionResultStatus.Success)
await speechRecognizer.ContinuousRecognitionSession.StartAsync();
}
InitializeSpeechRecognizer is called in MainPage
When I activate app I can see in debug window state changes. After I activate another app nothings happen :(
Thanks for any idea!
you have to use a BackgroundWorker thread for your application to work while not in focus.
backgroundWorker1.RunWorkerAsync(testFunction);
https://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx

How to show a modal window in windows 10 universal app?

When I use Mail univesal app in windows 10, when i add an account (setting->accounts->add account), it seems popup a modal window to choose an account. I try to use MessageDialog, but i can't put any custom content into it.
EDIT : this is the screenshot
Is someone knows how to implement it or there is some api can do it?
Note: When this window open, you even can't Minimize/Maximize/Close the main Window. So, it is definitely a modal window.
I haven't used it myself yet but i believe you're looking for ContentDialog api.
var dialog = new ContentDialog() {
Title = "Lorem Ipsum",
MaxWidth = this.ActualWidth // Required for Mobile!
Content = YourXamlContent
};
dialog.PrimaryButtonText = "OK";
dialog.IsPrimaryButtonEnabled = false;
dialog.PrimaryButtonClick += delegate {
};
var result = await dialog.ShowAsync();
msdn guidlines for dialogs: link
msdn ContentDialog API: link
You can easily create a new view like this, for example in your App.xaml.cs:
public static async Task<bool> TryShowNewWindow<TView>(bool switchToView)
{
var newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
var frame = new Frame();
frame.Navigate(typeof(TView), null);
Window.Current.Content = frame;
newViewId = ApplicationView.GetForCurrentView().Id;
});
var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
if (switchToView && viewShown)
{
// Switch to new view
await ApplicationViewSwitcher.SwitchAsync(newViewId);
}
return viewShown;
}
For further information, take a look at those two guides:
Guidelines for multiple windows
Quickstart: Creating multiple windows for an app (XAML)
If you use Template10 project template, you can use the ModalDialog control : https://github.com/Windows-XAML/Template10/wiki/Docs-%7C-Controls#modaldialog

ShellToast Navigation in notification

I am using ShellToast in ScheduledAgent.cs on my App, when I want to click on notification display by ShellToast, I want to navigate to different my second page, but when I try it nothing happen
protected override void OnInvoke(ScheduledTask task)
{
var toast = new ShellToast
{
Title = "KWTtest",
Content = toastMessage
};
toast.NavigationUri = new Uri("/View/SettingsPage.xaml",
UriKind.RelativeOrAbsolute);
toast.Show();
NotifyComplete();
}
}
This is the correct code. It works in my application.
You get a toast notification?
If you click on the notification, the application does not open completely?
Or application is opened after you click on the notification, but start on the main page?

Windows Phone Toast Notification Not Shown [duplicate]

In my application I want to notify the user with the ShellToast.
Just by running...
var toast = new ShellToast
{
Title = "Nom nom nom!",
Content = "More! More! Keep feeding me!",
};
toast.Show();
...makes nothing happen, and as I understand it needs to be run from a ScheduledTaskAgent. But how do I run this on command, and make sure it only run once?
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.
If you want to have a UX similar to that of ShellToast use the Coding4fun toolkit ToastPrompt control. Here's a code snippet showing how to use it:
private void ToastWrapWithImgAndTitleClick(object sender, RoutedEventArgs e)
{
var toast = GetToastWithImgAndTitle();
toast.TextWrapping = TextWrapping.Wrap;
toast.Show();
}
private static ToastPrompt GetToastWithImgAndTitle()
{
return new ToastPrompt
{
Title = "With Image",
TextOrientation = System.Windows.Controls.Orientation.Vertical,
Message = LongText,
ImageSource = new BitmapImage(new Uri("../../ApplicationIcon.png", UriKind.RelativeOrAbsolute))
};
}
Running this code snippet shows the following:
Just a small update: using ShellToast when the app is in foreground, is now possible, when using Windows Phone 8 Update 3. Though, they are obscured by other activity such as a phone call or the lock screen. Source

Categories

Resources