1

我看了这个样本:

http://www.dotnetfunda.com/articles/article811-simplest-way-to-implement-multilingual-wpf-application.aspx

但是,此示例显示了如何将字符串输入 GUI。

如何将字符串放入变量中。

我想显示一个 messagebox ,其中包含资源文件中的字符串。

在此先感谢家伙

4

1 回答 1

1

您可以使用ResourceDictionary.Item这是修改后的示例代码以使其执行您想要的操作。

Class MainWindow
    Dim dict As ResourceDictionary = New ResourceDictionary()
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        SetLanguageDictionary()
        MessageBox.Show(dict.Item("greeting").ToString)
    End Sub

    Private Sub SetLanguageDictionary()

        Select Case (Thread.CurrentThread.CurrentCulture.ToString())
            Case "en-US"
                dict.Source = New Uri("..\Resources\StringResources.xaml", UriKind.Relative)
            Case "fr-CA"
                dict.Source = New Uri("..\Resources\StringResources.fr-CA.xaml", UriKind.Relative)
            Case Else
                dict.Source = New Uri("..\Resources\StringResources.xaml", UriKind.Relative)
        End Select
    End Sub
End Class

和我正在使用的资源文件

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:system ="clr-namespace:System;assembly=mscorlib" >        
    <system:String x:Key="greeting">Hello World</system:String>
</ResourceDictionary>
于 2012-12-22T21:21:22.240 回答