我想本地化我在 app.xaml 中制作的应用栏,但是当我尝试绑定(bind)栏项目的文本时,它说文本不能为空,我已经尝试了本地化应用栏的其他示例,但没有一个是为可在所有页面上使用的应用栏工作..
最佳答案
您可以在 App.xaml
中使用一些伪造的 Text
声明一个全局应用栏,例如:
<Application
x:Class="PhoneApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<!--Application Resources-->
<Application.Resources>
<local:LocalizedStrings xmlns:local="clr-namespace:PhoneApp1" x:Key="LocalizedStrings"/>
<shell:ApplicationBar x:Key="GlobalAppBar">
<shell:ApplicationBarIconButton Text="TEST" IconUri="/Assets/check.png"/>
</shell:ApplicationBar>
</Application.Resources>
<Application.ApplicationLifetimeObjects>
<!--Required object that handles lifetime events for the application-->
<shell:PhoneApplicationService
Launching="Application_Launching" Closing="Application_Closing"
Activated="Application_Activated" Deactivated="Application_Deactivated"/>
</Application.ApplicationLifetimeObjects>
</Application>
在 App.xaml.cs
中应用本地化:
var appBar = App.Current.Resources["GlobalAppBar"] as ApplicationBar;
((ApplicationBarIconButton) appBar.Buttons[0]).Text = AppResources.AppBarButtonText;
现在你可以在 App
的任何地方使用全局 AppBar
,只需在 PhoneApplicationPage
的代码后面进行初始化:
public MainPage()
{
InitializeComponent();
ApplicationBar = App.Current.Resources["GlobalAppBar"] as ApplicationBar;
}
关于c# - Windows Phone 8 中应用程序栏的本地化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17651070/