Adr*_*n S 0 c# wpf xaml internationalization uiculture
如何正确设置文化以使标签的内容为“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>
Run Code Online (Sandbox Code Playgroud)
TextTextBlock的属性有 type string,因此转换器用于将 DateTime 转换为应用巴西风格的字符串。
ContentLabel的属性具有 type object。由于 DateTime 是一个对象,因此不使用转换器,因此您的 ConverterCulture 将被忽略。转换为 String 是由 ContentStringFormat 使用默认语言完成的。
为了获得您想要的结果,您可以Language="pt-BR"向标签添加一个属性。