2012-12-22 235 views

回答

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 

和我的resourcefile用

<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> 
+0

它的工作! (0).item code ... S = Me.Resources.MergedDictionaries.Item(0).Item(「login」)。ToString 謝謝! –