繁体   English   中英

如何在WP8中本地化DatePicker和TimePicker

[英]How to localize DatePicker and TimePicker in WP8

我试图在WP7上本地化与工具包相关的DatePicker和TimePicker,但我不确定如何访问Header和应用程序栏文本。 我找不到任何显示完成这些任务的方法的链接。 是否有任何有用的链接或是否有人知道如何实现这许多?

  1. 最简单的方法来下载最新版Toolkit(2011年11月)的源代码和样本,默认情况下为DatePickerTimePicker本地化。
  2. 将其作为项目参考添加到您的解决方案中。

如果您在2011年11月之前拥有Toolkit版本,

  1. 再次将其添加为解决方案中的项目参考
  2. 在一旁,项目就在你的解决方案中。 添加必要的resx文件。 您可以看到有一个默认的Resources.resx文件,其中包含日期选择器的英文文本。 为其他语言添加必要的resx文件。

这很简单:参数 - 语言。 Xaml代码:

<toolkit:DatePicker Language="ru-RU" Margin="-12, 0" Value="{Binding BirthDate, Mode=TwoWay}" />

另一种不修改XAML源的替代方法是在页面加载后修改“HeaderTitle”TextBlock。

    /// <summary>
    /// Called from app.xaml.cs if the user navigates to the DatePickerPage
    /// </summary>
    /// <param name="page">The page.</param>
    public static void DatePickerHook(PhoneApplicationPage page)
    {
        // Somehow modify the text on the top of the page...
        LoopThroughControls(page, (ui => {
            var tb = ui as TextBlock;
            if (tb != null && tb.Name == "HeaderTitle")
            {
                tb.Text = "<<Local Translation>>";
            }
        }));
    }

    /// <summary>
    /// Applies an action to every element on a page
    /// </summary>
    /// <param name="parent">The parent.</param>
    /// <param name="modifier">The modifier.</param>
    private static void LoopThroughControls(UIElement parent, Action<UIElement> modifier)
    {
        int count = VisualTreeHelper.GetChildrenCount(parent);
        if (count > 0)
        {
            for (int i = 0; i < count; i++)
            {
                UIElement child = (UIElement)VisualTreeHelper.GetChild(parent, i);
                modifier(child);
                LoopThroughControls(child, modifier);
            }
        }
        return;
    }

以下是描述对app.xaml.cs的修改的博客文章的链接: http ://blog.dotnetframework.org/2015/11/09/localise-datepicker-in-wp8-silverlighttoolkit-using-hooks/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM