我有 2 个字段,我想将其格式化为一个 TextBlock,例如:“{0} of {1} hours used”。
目前有:
<TextBlock Text="{Binding HoursEntered}" />
<TextBlock Text=" of " />
<TextBlock Text="{Binding EstimatedHours}" />
<TextBlock Text=" hours used " />
正在查看单个字段的 StringFormat,但这似乎仅适用于 WPF,不适用于 Silverlight:
<TextBlock Text="{Binding Path=HoursEntered, StringFormat='{0} of XX hours used'}"/>
我想使用 MultiBinding,但这在 Silverlight 3 中也不可用吗?
如何在 Silverlight 3 xaml 中使用多个绑定(bind)字段创建格式字符串?
最佳答案
您可以将文本放在绑定(bind)源中的只读字符串中
Public ReadOnly Property HoursUsedMessage() As String
Get
Return String.Format("{0} of {1} hours used", _hoursEntered, _estimatedHours)
End Get
End Property
只需确保您还在 HoursEntered 和 EstimatedHours setter 中为该属性发出属性通知
关于silverlight - 在 XAML 中的一个 TextBlock 中格式化多个绑定(bind)字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2063382/