如何在Windows Phone 8中执行某些功能后显示吐司

时间:2013-12-03 08:32:47

标签: c# windows-phone-8 windows-phone-8-emulator

我希望在执行某些功能后显示类似吐司的内容。我有一个保存按钮,我希望它按下然后应该显示文本记录保存等吐司​​。我阅读的帖子显示吐司仅适用于背景代理。我知道有人会给我很好的指导。请指明一些代码。

由于

3 个答案:

答案 0 :(得分:5)

您可以使用Toast Prompt from the Coding4Fun Toolkit通过代码执行Toast通知。在引用工具包(理想情况下通过NuGet)后,您可以像这样使用它:

ToastPrompt toast = new ToastPrompt();
toast.Title = "Your app title";
toast.Message = "Record saved.";
toast.TextOrientation = Orientation.Horizontal;
toast.MillisecondsUntilHidden = 2000;
toast.ImageSource = new BitmapImage(new Uri("ApplicationIcon.png", UriKind.RelativeOrAbsolute));

toast.Show();

答案 1 :(得分:5)

我更喜欢我的应用中的ProgressIndicator,但您可以使用PopupToastPrompt

示例project

// popup member
private Popup popup;

// creates popup
private Popup CreatePopup()
{
    // text
    TextBlock tb = new TextBlock();
    tb.Foreground = (Brush)this.Resources["PhoneForegroundBrush"];
    tb.FontSize = (double)this.Resources["PhoneFontSizeMedium"];
    tb.Margin = new Thickness(24, 32, 24, 12);
    tb.Text = "Custom toast message";

    // grid wrapper
    Grid grid = new Grid();
    grid.Background = (Brush)this.Resources["PhoneAccentBrush"];
    grid.Children.Add(tb);
    grid.Width = this.ActualWidth;

    // popup
    Popup popup = new Popup();
    popup.Child = grid;

    return popup;
}

// hides popup
private void HidePopup()
{
    SystemTray.BackgroundColor = (Color)this.Resources["PhoneBackgroundColor"];
    this.popup.IsOpen = false;
}

// shows popup
private void ShowPopup()
{
    SystemTray.BackgroundColor = (Color)this.Resources["PhoneAccentColor"];

    if (this.popup == null)
    {
        this.popup = this.CreatePopup();
    }

    this.popup.IsOpen = true;
}

// shows and hides popup with a delay
private async void ButtonClick(object sender, RoutedEventArgs e)
{
    this.ShowPopup();

    await Task.Delay(2000);

    this.HidePopup();
}

Custom toast message

答案 2 :(得分:1)

 using Windows.UI.Notifications;

 var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

 var txtNodes = toastXmlContent.GetElementsByTagName("text");
 txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("First Line"));
 txtNodes[1].AppendChild(toastXmlContent.CreateTextNode("Second Line" ));

 var toast = new ToastNotification(toastXmlContent);
 var toastNotifier = ToastNotificationManager.CreateToastNotifier();
 toastNotifier.Show(toast);