c# - Windows Phone 8 中应用程序栏的本地化

标签 c# xaml windows-phone-8 windows-phone

我想本地化我在 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/

相关文章:

c# - System.Device.Location.GeoCooperativeWatcher.Position.Location.Speed 始终为 NaN

c# - 无法单击以编程方式添加的按钮

c# - 有没有一个WPF库可以绘制数学表达式?

c++11 - 为 Windows Phone 8 构建 C++11?

xaml - TextBlock 中的多种颜色

xaml - xaml 中的逻辑 NOT

html - 为什么 Windows Phone(7 或 8)允许点击 divs?

c# - 如何以编程方式将参数传递给 Windows 服务的 OnStart 方法?

c# - 当光标悬停在 asp.net 网站中的图像上时如何更改图像

.net - Resharper 不能很好地与 XAML 配合使用?