c# - 文本文字中的 WPF 绑定(bind)

标签 c# wpf

有没有办法在绑定(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) RunText 属性。我一直在用它:

<TextBlock>
    Hello
    <Run Text="{Binding CurrentUser}" />,
    how are you?
</TextBlock>

StringFormat 方法很好,但是使用带有绑定(bind)的 Run 允许使用值转换器。

关于c# - 文本文字中的 WPF 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6708739/

相关文章:

c# - FromBody 收到的帖子导致序列化错误

c# - 两个物体在什么增量时间发生碰撞?

c# - WPF RichTextBox - 选定的 block ?

.net - SplashScreen.Close() 窃取 MainWindow 的焦点

c# - Entity Framework : No database connection has been configured for this model

c# - 加速 ASP MVC 单元测试

c# - ScriptControlDescriptor.AddProperty 和只读属性

c# - 如何使用 ActionFilterAttribute 记录运行时间?

c# - 为什么这种简单的风格不适用?

c# - 当我运行 WPF MVVM 应用程序时,显示主窗口的两个实例