如何在 C# (WPF) 中获取字符串资源?

Mic*_*ers 4 c# wpf localization localizable.strings

我知道如何从 XAML 中的字符串资源获取资源:

{Binding OK, Source={StaticResource LocStrings}}
Run Code Online (Sandbox Code Playgroud)

但是,我想直接在 C# 中使用本地化字符串,例如

someString = Resources["LocStrings"]["StringId"];
Run Code Online (Sandbox Code Playgroud)

但这不能编译。

NoO*_*One 7

你需要这样的东西:

var myText = this.FindResource("LocStrings") as string;
Run Code Online (Sandbox Code Playgroud)

我想,您可以更改this为您的资源所在的位置。

更新:

通常,这就是我对全局资源的使用:

var myText = Application.Current.FindResource("resourceName") as string;
Run Code Online (Sandbox Code Playgroud)