Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

ConverterCulture only works on OneWay binding. Why?

$
0
0

We are currently localizing our WPF application for different cultures.  Everywhere a date is displayed, we use the format "d MMM yyyy", e.g. 30 Sep 2016.  We want the month to be in the localized language.  In our dialog window, I changed the XAML to read as follows:

<userControls:CITTextBlock Grid.Row="2" Grid.Column="1"
  Text="{Binding DateOfBirth, StringFormat={}{0:d MMM yyyy}, ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}"
  ToolTipText="{Binding DateOfBirth, StringFormat={}{0:d MMM yyyy}, ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}"
  Style="{StaticResource CITTextBlockAutoToolTip}"
  Margin="{StaticResource StandardLabelMargin}"/>

When I did this, the date remained in English, regardless of the current thread and UI culture.  At first, I did this in the code-behind:

   /// </summary>
   public ArchiveBeforeDeleteDialog() {
       InitializeComponent();
       this.Language = XmlLanguage.GetLanguage(LocalizationSettings.Current.CurrentCulture.ToString());
   }
It then worked.  I don't know why, but it just worked.  I would have thought the ConverterCulture attribute in the binding would have taken care of this.  I noticed that it did work in other windows and controls.  What I found was that if the binding mode was set to OneWay, it worked.  This was a TextBlock and would not be updated by the user or in code-behind.  So when I added the Mode attribute to the binding (below), it worked, even when I removed setting the Language in the code-behind.
  Text="{Binding DateOfBirth, Mode=OneWay, StringFormat={}{0:d MMM yyyy}, ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}"
  ToolTipText="{Binding DateOfBirth, Mode=OneWay, StringFormat={}{0:d MMM yyyy}, ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}"
So, my question is: Why does setting the Mode to OneWay suddenly cause the ConverterCulture to work?


Viewing all articles
Browse latest Browse all 18858

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>