WPF绑定在文本文字中

Ada*_*kis 12 c# wpf

有没有办法在绑定表达式中执行此操作:

Text="Hello {Binding CurrentUser}"
Run Code Online (Sandbox Code Playgroud)

即:

<TextBlock HorizontalAlignment="Right" Foreground="#3163AB" Margin="0,0,0,5" 
    FontWeight="Bold" Text="Hello {Binding CurrentUser}" />
Run Code Online (Sandbox Code Playgroud)

显然我可以把它分成两个单独的文本块,但这会更好.

Ros*_*oss 16

从.NET 4开始,可以绑定Texta 的属性Run.我用它所有的时间:

<TextBlock>
    Hello
    <Run Text="{Binding CurrentUser}" />,
    how are you?
</TextBlock>
Run Code Online (Sandbox Code Playgroud)

StringFormat方法很好,但使用带绑定的Run允许使用Value Converters.


Eti*_*tel 9

你正在寻找的StringFormat财产Binding.

Text="{Binding CurrentUser, StringFormat=Hello {0}}"
Run Code Online (Sandbox Code Playgroud)


Vla*_*lad 6

Text="{Binding CurrentUser, StringFormat=Hello {0}}"
Run Code Online (Sandbox Code Playgroud)

应该做.