2

我有以下代码:

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# 版本,没有问题。

谢谢大家。

4

1 回答 1

1

您没有遵循 VB.NET 扩展方法规则。这表明:

  • 您必须在模块中编写扩展方法,而不是在类中
  • 他们必须有<Extension>属性
  • 使用它们的源代码文件必须有Imports该模块的语句。

并且需要VS2010或更高版本。MSDN 库文章在此处

于 2012-11-05T20:24:02.427 回答