【发布时间】:2012-07-19 20:47:38
【问题描述】:
我正在尝试本地化与 WP7 上的工具包关联的 DatePicker 和 TimePicker,但我不确定如何访问 Header 和应用程序栏文本。我找不到任何显示完成这些任务的方法的链接。是否有任何有用的链接或有人知道如何完成这些链接?
【问题讨论】:
标签: c# windows-phone-7 xaml datepicker timepicker
我正在尝试本地化与 WP7 上的工具包关联的 DatePicker 和 TimePicker,但我不确定如何访问 Header 和应用程序栏文本。我找不到任何显示完成这些任务的方法的链接。是否有任何有用的链接或有人知道如何完成这些链接?
【问题讨论】:
标签: c# windows-phone-7 xaml datepicker timepicker
DatePicker 和 TimePicker。 如果您拥有 2011 年 11 月之前的 Toolkit 版本,
【讨论】:
很简单:参数-语言。 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/
【讨论】: