2012-11-05 78 views
2

我有以下代碼:擴展system.windows.application不承認

Private Sub LocalizationComboBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) 
    Thread.CurrentThread.CurrentUICulture = TryCast(e.AddedItems(0), CultureInfo) 
    Application.Current.SaveCulture() 
    Application.Current.Refresh() 
End Sub 

而且我後來實現這個:

Public NotInheritable Class ApplicationExtensions 
Public Shared Sub Refresh(app As Application) 
    DirectCast(HtmlPage.Window.GetProperty("location"), ScriptObject).Invoke("reload") 
End Sub 

Public NotInheritable Class ApplicationExtensions 
    Private Sub New() 
    End Sub 
    Public Shared Sub Refresh(app As Application) 
     DirectCast(HtmlPage.Window.GetProperty("location"), ScriptObject).Invoke("reload") 
    End Sub 

    Public Shared Sub LoadCulture(app As Application) 
     Try 
      If IsolatedStorageSettings.ApplicationSettings.Contains("language") Then 
       Dim language = TryCast(IsolatedStorageSettings.ApplicationSettings("language"), String) 
       If language IsNot Nothing Then 
        Thread.CurrentThread.CurrentUICulture = New CultureInfo(language) 
       End If 
      Else 
       app.SaveCulture() 
      End If 
     Catch 
      MessageBox.Show("Please, open Silverlight settings and enable Application Storage.") 
     End Try 
    End Sub 

    Public Shared Sub SaveCulture(app As Application) 
     Try 
      IsolatedStorageSettings.ApplicationSettings("language") = Thread.CurrentThread.CurrentUICulture.Name 
     Catch 
      MessageBox.Show("Please, open Silverlight settings and enable Application Storage.") 
     End Try 
    End Sub 
End Class 

不過,我得到一個錯誤說:

'SaveCulture'不是'System.Windows.Application'的成員 'Refresh'不是'System.Windows.Application'的成員 'SaveCulture'不是'System.Windows.Application'的成員

有人可以幫我解決這個問題嗎? 現在我應該提一下,我有這個C#版本,這沒有問題。

謝謝,你們都。

回答

1

您不符合VB.NET擴展方法規則。這決定了:

  • 你必須寫在一個模塊的擴展方法,而不是一類
  • 他們必須有<Extension>屬性
  • 使用它們必須具有模塊的Imports語句的源代碼文件。

和VS2010或更高。 MSDN Library文章is here