set culture of individual WPF user control

culture, user-controls, wpf

Solution

You can set the `FrameworkElement.Language` property of your control or apply the `xml:lang` attribute to the XAML of your control. The value you have to set is `en-US`.

The culture you set using this property/attribute affects how culture-specific strings are converted in the control. E.g. if you display a `DateTime` using the `D` (long date) format you get something like `Monday, 30 April 2012` when `xml:lang="en-US"` and `30. april 2012` when `xml:lang="da-DK"`.

However, if you specify a date in XAML like in

<my:uc1 x:Name="UserControl1" Date="4/30/2012" />

that date is parsed using `CultureInfo.InvariantCulture` (basically `en-US`). That is not the behavior you seem to describe. You are a bit vague in the description of you real problem but to verify my claim you can try to enter `30/4/2012` for the date and see that it fails to compile. It does that not only when the current culture of Visual Studio is `en-US` but also as it is in my case `da-DK` (where the date format is `d/M/yyyy`).

Problem

I have written a user control which is not compatible with cultures other than "en-US". Also it is inevitable to embed this user control in an application with a culture which is not "en-US". So is it possible to force the application to not to change this user control's culture? Its preferable to have a solution inside the user control. I have read this thread : Localizing a WinForms Application with Embedded WPF User Controls but I can not use WpfLocalization.LocalizationScope.SetCulture Does this function really exists ? And also there is a Localizable tag which can be set to False but It is just for resource definitions in .csproj files: http://msdn.microsoft.com/en-us/library/ms788718.aspx So is there anybody who has any idea about this problem ? More clarification : Suppose we have an application with culture X and a user control which is compatible with culture "en-US". This user control has a dependency property which is of DateTime type and it is getting its value by this way : ``` <my:uc1 x:Name="UserControl1" Date="4234/12/22" /> ``` When application culture is "en-US" user control will get "4234/12/22" but when the application culture is something else, it converts "4234/12/22" automatically to the application's own calendar and delivers "0744/04/08" to the user control and ruins every logic behind the user control ! It's completely a disaster. I want to prevent this conversion by setting the user control's culture exclusively to "en-US". Hope that I have clarified the situation enough.

Original source