Localization with WPF require you to set the text to be used as there are no language translations by default. Here is a search show a number of ways of doing it:
wpf mulitiple language support - Google Search[
^] and here is an article on CP that demonstates one way:
Simplest Way to Implement Multilingual WPF Application[
^]
Now, regarding your issue with the
DatePicker
control. There are two parts:
1. The calendar month and the abbreviated day-of-week names - you have a solution already - simply set the culture.
2. Altering the
TextBox
text message to a localize message.
You have 2 choices:
a) extract and create your own template - not ideal
b) to progmatically change the text with your own - this is the method that I will demonstrate below.
Here is a working solution...
XAML
<DatePicker x:Name="MyDatePicker"
Loaded="MyDatePicker_OnLoaded"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Width="200"/>
Code-Behind:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
CultureInfo cultureInfo = new CultureInfo("fa-IR");
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
}
private void MyDatePicker_OnLoaded(object sender, RoutedEventArgs e)
{
DatePicker datePicker = sender as DatePicker;
if (datePicker is null)
return;
DatePickerTextBox pickerTextBox =
datePicker.GetChildOfType<DatePickerTextBox>();
if (pickerTextBox is null)
return;
ContentControl contentControl = pickerTextBox
.Template
.FindName("PART_Watermark", pickerTextBox) as ContentControl;
if (contentControl is null)
return;
contentControl.Content = "تاریخ را انتخاب کنید";
}
}
Extension Method:
public static class DependencyObjectExtensions
{
public static T GetChildOfType<T>(this DependencyObject depObj)
where T : DependencyObject
{
if (depObj == null) return null;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
var child = VisualTreeHelper.GetChild(depObj, i);
var result = (child as T) ?? GetChildOfType<T>(child);
if (result != null) return result;
}
return null;
}
}
I have hard-coded the text in the example. If you're only using one language, this is fine. If not, refer to the links at the beginning of this solution.