有没有办法在绑定(bind)表达式中做到这一点:
Text="Hello {Binding CurrentUser}"
即:
<TextBlock HorizontalAlignment="Right" Foreground="#3163AB" Margin="0,0,0,5"
FontWeight="Bold" Text="Hello {Binding CurrentUser}" />
显然我可以将它分成两个单独的文本 block ,但这样会好得多。
最佳答案
从 .NET 4 开始,可以绑定(bind) Run
的 Text
属性。我一直在用它:
<TextBlock>
Hello
<Run Text="{Binding CurrentUser}" />,
how are you?
</TextBlock>
StringFormat 方法很好,但是使用带有绑定(bind)的 Run 允许使用值转换器。
关于c# - 文本文字中的 WPF 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6708739/