Dot-Net

將文本添加到綁定的 TextBlock

  • August 20, 2011

我想在數據綁定文本塊中添加文本:

<TextBlock Text="{Binding Title}" />

顯示的文本是:

"My title"

我想要展示的是:

This is "My title"

您可以使用StringFormat綁定的屬性:

<TextBlock Text="{Binding Title, StringFormat=This is {0}}"></TextBlock> 

查看此部落格文章了解更多資訊:WPF String.Format in XAML with the StringFormat attribute

引用自:https://stackoverflow.com/questions/7130859