扩展system.windows.application无法识别

时间:2012-11-05 19:24:36

标签: vb.net silverlight-4.0 extension-methods

我有以下代码:

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 个答案:

答案 0 :(得分:1)

您没有遵循VB.NET扩展方法规则。这决定了:

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

需要VS2010或更高版本。 MSDN Library文章is here