Silverlight 是否支持绑定中的 StringFormat? [英] Does Silverlight support StringFormat in binding?
问题描述
我知道 WPF 3.5 SP1 支持绑定中的 StringFormat
,但 Silverlight 可以这样做吗?我认为它可以,但该死的如果我能让它工作!
I know that WPF 3.5 SP1 supports a StringFormat
in a binding, but can Silverlight do the same? I thought it could, but damned if I can make it work!
这是我的 XAML 的一个片段:
Here's a snippet of my XAML:
<TextBlock Text="{Binding StartTime, StringFormat=t}" />
它编译正常,但是当它到达浏览器时出现运行时错误...
It compiles OK, but I get a runtime error when it gets to the browser...
推荐答案
Silverlight 3 及以下版本没有,但您可以使用值转换器并在绑定中指定 ConverterParamenter.您必须通过从 IValueConverter 派生一个类来创建自己的值转换器,就像我展示的 此处.
Silverlight 3 and below do not, but you can use a Value Converter and specify the ConverterParamenter in the binding. You'll have to create your own Value Converter by deriving a class from IValueConverter like I've shown here.
Silverlight 4 及更高版本具有与 WPF 相同的 StringFormat 绑定属性.
Silverlight 4 and later has the same StringFormat binding property as WPF.
这篇关于Silverlight 是否支持绑定中的 StringFormat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!