Wpf 从资源文件中获取字符串
我看了这个样本: 但是,此示例显示了如何将字符串放入GUI 如何将字符串放入变量中 我想显示一个messagebox,其中包含资源文件中的字符串 提前谢谢 Guy您可以使用这个示例代码,它经过修改后可以实现您想要的功能Wpf 从资源文件中获取字符串,wpf,vb.net,resourcedictionary,Wpf,Vb.net,Resourcedictionary,我看了这个样本: 但是,此示例显示了如何将字符串放入GUI 如何将字符串放入变量中 我想显示一个messagebox,其中包含资源文件中的字符串 提前谢谢 Guy您可以使用这个示例代码,它经过修改后可以实现您想要的功能 Class MainWindow Dim dict As ResourceDictionary = New ResourceDictionary() Public Sub New() ' This call is required by the
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>
你好,世界
您可以使用修改后的示例代码,使其执行您希望的操作
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>
你好,世界
它正在工作!!!我缺少一个。项目(0)。项目代码…:S=Me.Resources.MergedDictionaries.Item(0.Item)(“登录”)。ToString谢谢!!!它的工作!!!我缺少一个。项目(0)。项目代码…:S=Me.Resources.MergedDictionaries.Item(0.Item)(“登录”)。ToString谢谢!!!