App Hub
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (10 posts)

Converter culture issues

Last post 7/28/2011 4:19 PM by Devscope.. 9 replies.
  • 7/26/2011 1:44 AM

    Converter culture issues

    I'm having this issue with both the Emulator fo 7.1 SDK Beta 2 and a device running Mango.
    Although CultureInfo.CurrentCulture is "pt-PT", the culture parameter of converter methods receives "en-US".

    Where is this comming from?

  • 7/26/2011 1:35 PM In reply to

    Re: Converter culture issues

    I'm assuming you are using something like this:

    int number = 10 
    string text = number.ToString() 

    If CultureInfo.CurrentCulture is correct, why don't you just use:

    int number = 10  
    string text = number.ToString(CultureInfo.CurrentCulture) 

  • 7/27/2011 9:21 PM In reply to

    Re: Converter culture issues

    I'm writting a value converter (IValueConverter) and I'm receiveing a culture as parameter that is different from CultureInfo.CurrentCulture:

    1 public class MyValueConverter : IValueConverter  
    2 {  
    3     public object Convert(object value, Type targetType, object parameter, CultureInfo culture)  
    4     {  
    5         // ..  
    6     }  
    7  
    8     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)  
    9     {  
    10         throw new NotImplementedException();  
    11     }  
    12

    Where is this culture value comming from?
  • 7/27/2011 9:35 PM In reply to

    Re: Converter culture issues

    Check Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture, what values do they show you?
  • 7/27/2011 10:20 PM In reply to

    Re: Converter culture issues

    I'm probably not making myself clear.

    I know where the get the current thread's culture and UI culture.

    What I want to know is where the value of the culture parameter come from.

    Meanwhile, I've been looking around the documentation (as I should have done from the start) and it says the the culture parameter is the "culture of the conversion".

    The documentation also says that the value of the culture parameter comes from:
    1. The converter looks for the ConverterCulture property on the Binding object.
    2. If the ConverterCulture value is null, the value of the Language property is used.

    So, I guess, my guess my question is where does the value of en-US come from when both the CurrentCulture and CurrentUICulture are pt-PT?

    And, what's this culture supposed to be used for? Culture and UICulture?

  • 7/27/2011 10:36 PM In reply to

    Re: Converter culture issues

    I was assuming that CurrentCulture or CurrentUICulture was en-US, there goes that theory... let me make some tests and I'll get back to this later on! ;)
  • 7/27/2011 11:57 PM In reply to

    Re: Converter culture issues

    From "Silverlight 4 Unleashed" by Laureant Bunion, page 141 ("Diving into Data Bindings"):

    "Even if the application’s CurrentCulture and CurrentUICulture are set to a culture other
    than en-US, this will not be applied
    to the StringFormat. This annoying fact can be
    worked around by setting the Language property on the UserControl in which the
    binding is applied. The Language property can be applied in XAML or in code, as shown

    Language = XmlLanguage.GetLanguage("it-IT");"

    My suggestion goes to just try to do this, by setting the Language property with the CurrentCulture value...

    Also, on your post above, looking at the FrameworkElement.Language documentation it stats:

    "The default is an XmlLanguage object that has its IetfLanguageTag value set to the string "en-US"."
  • 7/28/2011 12:48 AM In reply to

    Re: Converter culture issues

    After taking another look at the documentation I tried that and it worked.

    But the question remins: WHY? OH, WHY? :)
  • 7/28/2011 9:09 AM In reply to

    Re: Converter culture issues

    And that really is the BIG question!...

    This one is so freaky, that I think I'm gonna write a post on my blog about it... ;)
Page 1 of 1 (10 posts) Previous Discussion Next Discussion