2016-07-15 85 views
0

如何正確設置文化以便標籤的內容是「seg」(星期一用巴西葡萄牙語)?在標籤中設置日期格式的文化

爲TextBlock設置ConverterCulture文本綁定將其更改爲pt-BR,但爲標籤的內容綁定設置ConverterCulture不會。下面的XAML。

<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> 

回答

2

TextBlock的Text酒店式string,使轉換器用於日期時間轉換爲應用巴西的風格串。

該標籤的Content屬性的類型爲object。由於DateTime是一個對象,因此不使用轉換器,因此您的ConverterCulture將被忽略。轉換爲String是由ContentStringFormat使用默認語言創建的。

爲了得到您想要的結果,您可以將Language="pt-BR"屬性添加到您的標籤。