本地化默认的Windows手机日期选择器

时间:2012-02-15 14:57:20

标签: windows-phone-7 localization toolkit

我已经对整个应用进行了本地化,但无法本地化日期选择器。论坛中的一些搜索给了我一些答案like this one

但是我找不到一个带有resx的属性文件夹,用于工具箱的不同lang!我有jus在解决方案资源管理器中添加了工具包引用,并且能够访问日期选择器。我创建了一个名为toolkit.content的文件夹来放置ok和取消图像。

那么如何为工具包日期选择器添加resx :(

3 个答案:

答案 0 :(得分:2)

您还可以创建一个继承自原始DatePicker的自定义控件。

 public class MyDatePicker : Microsoft.Phone.Controls.DatePicker
{
    public string PickerPageHeader
    {
        get { return (string)GetValue(PickerPageHeaderProperty); }
        set { SetValue(PickerPageHeaderProperty, value); }
    }

    // Using a DependencyProperty as the backing store for PickerPageHeader.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty PickerPageHeaderProperty =
        DependencyProperty.Register("PickerPageHeader", typeof(string), typeof(MyDatePicker)
        , new PropertyMetadata("Choose date text in your language"));

    public MyDatePicker()
    {
        base.PickerPageUri = new Uri("/Sample;component/CustomControls/MyDatePickerPage.xaml?Header=" + PickerPageHeader, UriKind.Relative);
       //Don't forget to change the project name and xaml location
    }
}

在CustomControls文件夹中创建选择器页面xaml文件:

<toolkit:DatePickerPage
x:Class="Sample.MyDatePickerPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
/>

代码背后:

public partial class MyDatePickerPage : Microsoft.Phone.Controls.DatePickerPage
{
    public MyDatePickerPage ()
    {
        InitializeComponent();

        foreach (var item in base.ApplicationBar.Buttons)
        {
            IApplicationBarIconButton button = item as IApplicationBarIconButton;
            if (null != button)
            {
                if ("DONE" == button.Text.ToUpper())
                {
                    button.Text = "done in your language";
                }
                else if ("CANCEL" == button.Text.ToUpper())
                {
                    button.Text = "cancel in your language";
                }
            }
        }
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        (base.FindName("HeaderTitle") as TextBlock).Text = e.Uri.OriginalString.Substring(e.Uri.OriginalString.IndexOf("Header=") + 7);
        base.OnNavigatedTo(e);
    }
}

答案 1 :(得分:1)

您必须获取ToolKit的源代码并使用您的本地化重建它

WP7 ToolKit Source

答案 2 :(得分:0)

非常简单:参数 - 语言。 Xaml代码:

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