2014-10-02 152 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