Monthly Archives: May 2012

WPF default binding format culture

WPF formats non-string objects to a string using a fixed/hardcoded culture (en-US) regardless of the current culture (as in Thread.CurrentThread.CurrentCulture / CultureInfo.CurrentCulture).

Suppose you have a simple DataContext (ViewModel) like so :

public class Data
{
    public DateTime Now 
    { 
        get 
        { 
             return DateTime.Now; 
        } 
    }

    public string NowText 
    { 
        get 
        { 
              return DateTime.Now.ToString(); 
        } 
    }
}

Binding an instance of `Data` to a view, with two TextBlocks each of which using ‘Now’ and ‘NowText’ respectively will yield different results if your CurrentCulture is NOT en-US.

Working on an internationalizable WPF app I’ve found out this sad truth. I don’t fully understand why this happens but I’ve found a way to “fix it”.

Somewhere before any piece of UI is shown on the screen (for example in App.xaml.cs in ApplicationStartup) just place this little piece of code :

FrameworkElement.LanguageProperty.OverrideMetadata(
  typeof(FrameworkElement),
  new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

It sets for any FrameworkElement (TextBlock and Label are included) the formatting culture to the current culture. Of course you might need to change it again if the current culture changes (for example an on-the-fly UI language changes).

How to deal with unwanted LinkedIn invites

How many of haven’t received unwanted LinkedIn invites from people that claim to know you, been colleagues and you haven’t even heard of?

Like… so :

or like so :

Don’t be fooled, they’re just trying to get their recruitment bonus. The right choice? The “REPORT SPAM” button up above. Press it. They deserve it. The correct way would have been a private message but it’s more useful for the recruiters to add a new contact since they may need to contact him/her again.