我正在尝试在我的项目中使用PL,现在我坚持使用本地化。我将我的Resources和LocalizedStrings移动到了PL项目。我的LocalizedStrings看起来像这样:
namespace Activity.Localization
{
public class LocalizedStrings : INotifyPropertyChanged
{
public LocalizedStrings()
{
}
private static Resources.AppResources localizedResources = new Resources.AppResources();
public Resources.AppResources LocalizedResources { get { return localizedResources; } }
public void ResetResources()
{
OnPropertyChanged("LocalizedResources");
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}
}
和资源在Resources文件夹中(它是从Windows phone项目自动生成的)。
现在在我的视图中我有这个按钮(Windows Phone项目,MainPage.xaml):
<controls:MenuButton x:Name="btnStartGame"
Text="{Binding Path=LocalizedResources.btnStartGame, Source={StaticResource localization:LocalizedStrings}}"
Tap="btnStartGame_Click"
Height="80" Width="400"
FontSize="30" Margin="12"/>
它编译和构建但是当应用程序启动时我得到异常:
Cannot find a Resource with the Name/Key localization:LocalizedStrings
所以我认为我必须做一些改变以获得可移植库的本地化但是哪一个?如何更改它以使其工作?感谢
答案 0 :(得分:2)
您需要在App.xaml中添加StaticResource:
http://www.geekchamp.com/articles/localizing-a-windows-phone-app-step-by-step