簡體   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