WPF xml:lang/语言绑定
我如何绑定 Listbox 或 texblock 的 Language 属性(或 xml:lang 属性)。
我想以特定语言设置显示月份名称
例如:
<TextBlock x:Name="Date" xml:lang="{Binding Lang}">
<TextBlock.Text>
<MultiBinding StringFormat=" {0:dd.MMM.yyyy}-{1:dd.MMM.yyyy}">
<Binding Path="Date1"/>
<Binding Path="Date2"/>
</MultiBinding>
</TextBlock.Text>
结果应根据 Lang 属性:
01.Apr.2011 - 01.Apr.2011 en-US
或 01.Nis.2011 - 02.Nis.2011 tr-TR
或者....
它给出 XamlParseException : Language attribute无法转换为System.Windows.Markup.XmlLanguage类型(这不是确切的错误文本。)
有什么想法吗?
how can i bind Listbox's or texblock's Language attribute (or xml:lang attribute).
i want to show month names in the specific language setting
ex:
<TextBlock x:Name="Date" xml:lang="{Binding Lang}">
<TextBlock.Text>
<MultiBinding StringFormat=" {0:dd.MMM.yyyy}-{1:dd.MMM.yyyy}">
<Binding Path="Date1"/>
<Binding Path="Date2"/>
</MultiBinding>
</TextBlock.Text>
result should be according to Lang property:
01.Apr.2011 - 01.Apr.2011 en-US
or 01.Nis.2011 - 02.Nis.2011 tr-TR
or ....
it gives XamlParseException : Language attribute cannot convert to System.Windows.Markup.XmlLanguage type (that is not exact Error Text. )
Any Idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在应用程序的 Startup 事件中,添加以下指令:
它将整个应用程序的
Language
属性的默认值覆盖为当前区域性。编辑:好的,我误解了你的问题...
如果你想将
Language
属性绑定到包含IetfLanguageTag
的字符串,你需要一个转换器:在中声明转换器XAML 资源:
并在绑定中使用转换器:
In the
Startup
event of the application, add this instruction:It will override the default value of the
Language
property to the current culture, for the whole application.EDIT: ok, I had misunderstood your question...
If you want to bind the
Language
property to a string containing theIetfLanguageTag
, you need a converter:Declare the converter in the XAML resources:
And use the converter in the binding:
您可以创建附加属性并使用它。
XAML
you could create attached property and use it.
XAML
语言可以绑定到
CultureInfo
实例或string
区域性名称。为避免错误
根据请求在绑定集 ConverterCulture 上显式指定 ConverterCulture:(
Source={x:Static threading:Thread.CurrentThread}
用作示例,并且应该如果语言绑定到 DataContext 中的属性,则删除)Language can be bound to
CultureInfo
instance orstring
culture name.To avoid error
set ConverterCulture for that binding as requested:
(
Source={x:Static threading:Thread.CurrentThread}
is used as an example and should be removed if Language binds to property in the DataContext)