locked
How to force date picker take a specific culture ? RRS feed

  • Question

  • How to make Datepicker Display only English culture even though the user use any other culture in his device ?

    DesertQueen

    Tuesday, January 21, 2014 6:56 AM

Answers

  • Hi,

    You can try this one.

    Note :I have used two date picker control in this.You can use your control

    .xaml code

      <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">         
                <toolkit:DatePicker x:Name="datePicker" Value="2/3/2010"  ValueStringFormat="{}{0:D}" Margin="0,217,0,-217" GotFocus="datePicker_GotFocus_1" />
                <toolkit:DatePicker x:Name="secondatePicker" Value="2/3/2010"  ValueStringFormat="{}{0:D}" Margin="0,500,0,-217"  />
            </Grid>

    and .cs code

    namespace PhoneApp2
    {
        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            string culture;
            public MainPage()
            {
                InitializeComponent();
    
                // Sample code to localize the ApplicationBar
                //BuildLocalizedApplicationBar();
    
                culture= System.Threading.Thread.CurrentThread.CurrentCulture.Name;//Your current device culture 
                MessageBox.Show(culture);
               
            }
    
    
            protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                base.OnNavigatedTo(e);
    
    
                if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back)
                {
                    MessageBox.Show("hi");
                    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
    
                }
    
            }
    
            private void datePicker_GotFocus_1(object sender, RoutedEventArgs e)
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-CN");//Set culture on date picker yo wants
            }
    }

    Let me know if you got any problem

    Thanks

    • Marked as answer by DevWP Sunday, January 26, 2014 11:31 AM
    Tuesday, January 21, 2014 12:51 PM

All replies

  • Hi,

    You can use this System.Threading.Thread.CurrentThread.CurrentCulture for setting the display culture.

    for e.g if you  want show date picker specific culture english 

    then use this

      public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            public MainPage()
            {
                InitializeComponent();
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-Us");
            }
    }

    and other culture you can set as same.

    Thanks

    Tuesday, January 21, 2014 7:58 AM
  • But i want only the datePicker with that culture not all the page and application  

    DesertQueen

    Tuesday, January 21, 2014 11:03 AM
  • Hi,

    You can try this one.

    Note :I have used two date picker control in this.You can use your control

    .xaml code

      <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">         
                <toolkit:DatePicker x:Name="datePicker" Value="2/3/2010"  ValueStringFormat="{}{0:D}" Margin="0,217,0,-217" GotFocus="datePicker_GotFocus_1" />
                <toolkit:DatePicker x:Name="secondatePicker" Value="2/3/2010"  ValueStringFormat="{}{0:D}" Margin="0,500,0,-217"  />
            </Grid>

    and .cs code

    namespace PhoneApp2
    {
        public partial class MainPage : PhoneApplicationPage
        {
            // Constructor
            string culture;
            public MainPage()
            {
                InitializeComponent();
    
                // Sample code to localize the ApplicationBar
                //BuildLocalizedApplicationBar();
    
                culture= System.Threading.Thread.CurrentThread.CurrentCulture.Name;//Your current device culture 
                MessageBox.Show(culture);
               
            }
    
    
            protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                base.OnNavigatedTo(e);
    
    
                if (e.NavigationMode == System.Windows.Navigation.NavigationMode.Back)
                {
                    MessageBox.Show("hi");
                    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
    
                }
    
            }
    
            private void datePicker_GotFocus_1(object sender, RoutedEventArgs e)
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-CN");//Set culture on date picker yo wants
            }
    }

    Let me know if you got any problem

    Thanks

    • Marked as answer by DevWP Sunday, January 26, 2014 11:31 AM
    Tuesday, January 21, 2014 12:51 PM