Adrian S
Adrian S

Reputation: 544

Setting culture for date format in label

How to set the culture correctly so that the Label's content is "seg" (Monday in Brazilian Portuguese)?

Setting ConverterCulture for the TextBlock Text binding changes it to pt-BR, but setting ConverterCulture for the Label's Content Binding does not. XAML below.

<Window x:Class="CurrentCulture.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.Resources>
            <sys:DateTime x:Key="Td:Mon">2007-1-1</sys:DateTime>
        </Grid.Resources>
        <StackPanel>
            <Label Content="{Binding Source={StaticResource Td:Mon}, ConverterCulture=pt-BR}" ContentStringFormat="{}{0:ddd}"  />
            <TextBlock Text="{Binding Source={StaticResource Td:Mon}, ConverterCulture=pt-BR,StringFormat={}{0:ddd}}" />
        </StackPanel>
    </Grid>
</Window>

Upvotes: 0

Views: 1984

Answers (1)

Fratyx
Fratyx

Reputation: 5797

The Text property of TextBlock has type string, so the converter is used to convert DateTime to string applying the Brasilian style.

The Content property of the Label has type object. As DateTime is an object, no converter is used and so your ConverterCulture is ignored. The transforming to String is made by ContentStringFormat using the default language.

To get your desired result you can add an Language="pt-BR" attribute to your Label.

Upvotes: 5

Related Questions