silverlight - 在 XAML 中的一个 TextBlock 中格式化多个绑定(bind)字段

标签 silverlight xaml string silverlight-3.0

我有 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/

相关文章:

c# - 在 xmlns clr 命名空间 : 中找不到 Xamarin Forms 抛出异常

python - C++ 相当于 Python 字符串切片?

c# - 将音频文件流式传输到另一台计算机

.net - 找不到资源词典

c# - 如何高效画百点,C#/XAML

python - DataFrame 列将字典列表存储为字符串 : Parse it and build a new dataframe

regex - Perl:如何用它的值替换变量

c# - 如何绑定(bind)或以其他方式获取和设置资源中控件的值?

Silverlight 应用程序不运行。我收到无效或格式错误的应用程序错误

c# - 更新 GUI 的 BackgroundWorker