问题描述
我想在 Windows Phone 8.1 的 Android 中创建类似于 toast 通知"的内容.我想要的是,要显示的文本框,指示发生了某些事件的用户(如已配对"、连接丢失"...等).但是文本框应该会在几秒钟后在没有任何用户交互的情况下自动消失.我已经浏览了消息框和窗口中的弹出窗口.但两者都不符合我的需求,或者我必须使用 计时器回调来自动关闭它,这是不推荐的.
I want to create something similar to "toast notification" in Android in windows phone 8.1.What I want is, a text box to be displayed, indicating the user of some events happened ( like "Paired", "Connection Lost"...etc) . But the text box should get dismissed automatically after a few seconds without any user interaction.I have gone through Message Box, and Popup in windows. But both doesn't suite my needs, or I have to use a timer callback to dismiss it automatically, which is not recommended.
谁能建议一种在 Windows Phone 8.1 中实现此目的的方法
Can anyone suggest a method to achieve this in Windows Phone 8.1
推荐答案
您可以在其中添加一个静态类添加以下内容.之后,从您想要显示吐司的任何地方调用此 showText().只需传递布局根(父网格)和字符串即可显示.您可以根据需要自定义外观和感觉.
You can add a static class add following in that. After that call this showText() from wherever you want to show your toast.Just pass the layout root (parent grid) and string to display. You can customize your look and feel as you want.
public static void ShowToast(Grid layoutRoot, string message)
{
Grid grid = new Grid();
grid.Width = 300;
grid.Height = 60;
grid.Background = new Windows.UI.Xaml.Media.SolidColorBrush(Colors.Transparent);
grid.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
grid.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Bottom;
grid.Margin = new Thickness(0, 0, 0, 30);
TextBlock text = new TextBlock();
text.Text = message;
text.VerticalAlignment = VerticalAlignment.Center;
text.HorizontalAlignment = HorizontalAlignment.Center;
text.FontSize = 22;
grid.Children.Add(text);
layoutRoot.Children.Add(grid);
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 3);
timer.Tick += (sender, args) =>
{
layoutRoot.Children.Remove(grid);
timer.Stop();
};
timer.Start();
}
这篇关于如何创建类似于“吐司通知"的东西在 Windows Phone 8.1 中的 Android 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!