Ard*_*tin 5 c# messagebox windows-phone-8
我正在使用我的Windows Phone 8.1应用程序.我想在用户按回键时显示消息.我知道代码,但出了点问题.Visual Studio在MessageBox,MessageBoxResult下显示红线.
如何在Windows Phone 8.1中显示消息?我认为在WP7操作系统之后它已经改变了.
这是我的代码示例.
public MainPage()
{
this.InitializeComponent();
progRing.IsActive = true;
Window.Current.SizeChanged += Current_SizeChanged;
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
this.NavigationCacheMode = NavigationCacheMode.Required;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
}
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
string caption = "Stop music and exit?";
string message = "If you want to continue listen music while doing other stuff, please use Home key instead of Back key. Do you still want to exit?";
e.Cancel = MessageBoxResult.Cancel == MessageBox.Show(message, caption, MessageBoxButton.OKCancel);
base.OnBackKeyPress(e);
}
Run Code Online (Sandbox Code Playgroud)
Sau*_*321 18
从Windows.Phone.UI.Input命名空间判断,你的目标是基于WinRT XAML的应用而不是Silverlight WP8.1在WinRT中没有MessageBox.Show()方法你必须使用MessageDialog类加点是你可以自定义对话框上的按钮名称以及进程现在是异步的,这意味着在显示消息对话框时它不会阻止您的应用程序运行
using Windows.UI.Popups;
...
MessageDialog dialogbox= new MessageDialog("Your message content", "title");
await dialogbox.ShowAsync();
Run Code Online (Sandbox Code Playgroud)
JayDev的回答是完整和正确的
JayDev回答的一个问题是WinRT中没有"覆盖onBackKeyPress".这是你要做的:
using Windows.Phone.UI.Input
...
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//This should be written here rather than the contructor
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
//This is where all your 'override backkey' code goes
//You can put message dialog and/or cancel the back key using e.Handled = true;
}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
//remove the handler before you leave!
HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10115 次 |
| 最近记录: |