Reputation: 155
I'm trying to implement this code:
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
But getting an error: Type 'MessageBoxResult' is not defined Why is happening?
I'm using: Microsoft Visual Studio Professional 2013 Version 12.0.30501.00 Update 2 Microsoft .NET Framework Version 4.5.51641
Upvotes: 0
Views: 729
Reputation: 21889
If System.Windows didn't resolve then you had a Windows Phone Runtime app (targetting Windows Phone 8.1) rather than a Windows Phone Silverlight app (for either 8.0 or 8.1). Chubosaurus' steps will create a Silverlight app.
You can confirm in the Solution Explorer, which will show the target for the project. To use System.Windows and MessageBox you will need a Windows Phone Silverlight app.
If you have a Windows Phone 8.1 app you can use Windows.UI.Popups.MessageDialog instead
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
Upvotes: 0
Reputation: 8161
Nothing wrong with your code. It should work (I implemented it myself). So it has to be some linking error / install error / or project creation error.
So lets fix, so lets try this:
It should generate you a blank app, then lets try and create a MessageBox on the Page Loaded Event
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
If that doesn't work then we need to make sure that System.Windows is imported
Upvotes: 1