2014-10-02 79 views
0

我想实现这个代码:WPF8消息框

Dim result As MessageBoxResult = _ 
MessageBox.Show("Would you like to see the simple version?", _ 
"MessageBox Example", MessageBoxButton.OKCancel) 

If (result = MessageBoxResult.OK) Then 
    MessageBox.Show("No caption, one button.") 
End If 

但得到一个错误:类型“MessageBoxResult”为什么发生没有定义 ?

我使用的是:微软的Visual Studio 2013专业版12.0.30501.00更新2 Microsoft .NET Framework版本4.5.51641

+0

我编辑了自己的冠军。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 – 2014-10-03 00:53:34

+0

我看到了,谢谢 – 2014-10-03 12:46:13

回答

0

如果System.Windows未解决,那么您的Windows Phone运行时应用程序(定位Windows Phone 8.1)而不是Windows Phone Silverlight应用程序(适用于8.0或8.1)。 Chubosaurus的步骤将创建一个Silverlight应用程序。

您可以在解决方案资源管理器中进行确认,该工具将显示项目的目标。要使用System.Windows和MessageBox,您需要Windows Phone Silverlight应用程序。

Windows Phone Silverlight 8Windows Phone Silverlight 8.1

如果你有一款Windows Phone 8.1应用程序,你可以使用Windows.UI.Popups.MessageDialog代替 enter image description here

Async Function ShowMyDialog() As Task(Of Boolean) 
    Dim result As Boolean = False 
    Dim dialog As New Windows.UI.Popups.MessageDialog("Would you like to see the simple version?", "MessageDialog Example") 
    dialog.Commands.Add(New Windows.UI.Popups.UICommand("Ok", 
     Async Sub(command) 
      result = True 
      Dim okDialog As New Windows.UI.Popups.MessageDialog("No caption, one button.") 
      Await okDialog.ShowAsync() 
     End Sub)) 
    dialog.Commands.Add(New Windows.UI.Popups.UICommand("Cancel")) 
    dialog.DefaultCommandIndex = 0 
    dialog.CancelCommandIndex = 1 
    Await dialog.ShowAsync() 
    Return result 
End Function 
+0

非常感谢你。没有Silverlight版本,你是对的!否,您提供的代码示例我有工作解决方案。非常感谢你! – 2014-10-03 22:07:15

1

没有错,你的代码。它应该工作(我自己实现它)。所以它必须是一些链接错误/安装错误/或项目创建错误。

因此,让修复,所以让我们试试这个:

  • 文件 - >新建 - >项目
  • 选择模板 - > Visual Basic中 - > Store应用 - > Windows Phone的应用程序 - >空白应用程序(视窗电话的Silverlight)
  • 选择作为目标8.0

应该为你生成一个空白的应用程序,然后让ŧ RY并在页面加载事件

Imports System 
Imports System.Threading 
Imports System.Windows.Controls 
Imports Microsoft.Phone.Controls 
Imports Microsoft.Phone.Shell 
Imports System.Windows 

Partial Public Class MainPage 
    Inherits PhoneApplicationPage 

    ' Constructor 
    Public Sub New() 
     InitializeComponent() 

     SupportedOrientations = SupportedPageOrientation.Portrait Or SupportedPageOrientation.Landscape 

    End Sub 

    Private Sub PhoneApplicationPage_Loaded(sender As Object, e As RoutedEventArgs) 
     Dim result As MessageBoxResult = _ 
     MessageBox.Show("Would you like to see the simple version?", _ 
     "MessageBox Example", MessageBoxButton.OKCancel) 

     If (result = MessageBoxResult.OK) Then 
     ' Do whatever 
     End If 

    End Sub 
End Class 

创建一个消息如果不工作,那么我们需要确保System.Windows进口

  • 右键单击项目 - >属性
  • 点击参考
  • 确保System.Windows有一个勾号
+0

你是对的:** System.Windows **没有被选中...我检查了它,但是没有结果,仍然是同样的错误。但是当我尝试按照你的要求制作一个新项目时 - 一切工作正常。神秘主义...... – 2014-10-03 11:46:53