如何在WP8中本地化DatePicker和TimePicker



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

  1. 下载最新版本工具包(2011年11月)的Source和Samples的最简单方法,默认情况下,该工具包具有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/

最新更新