Binding the content of a Span

自闭症网瘾萝莉.ら 提交于 2020-02-01 00:41:09

问题


I have a window that displays text. There are two parts to the text: the first is fixed while the second needs to be the content of a DependencyProperty declared on the window.

I considered using a TextBlock containing two Spans, the first of which contains the fixed content and the second of which contains the variable content, but I can't see anything obvious on the Span class that would allow me to bind to the aforementioned DependencyProperty.

I'm currently using two Labels stacked side by side but this is ugly and doesn't help me if I wish to retrieve the content of the entire text block (as I do when displaying a ToolTip in the event that the window is too narrow to display the entire text block).

Can anyone help me to crack this seemingly simple problem? Thanks.


回答1:


If you're using .NET 4:

<TextBlock>
    <Run Text="Fixed:"/>
    <Run Text="{Binding Variable}"/>
</TextBlock>

Prior to .NET 4, the Run's Text property was not a dependency property.



来源:https://stackoverflow.com/questions/3356053/binding-the-content-of-a-span

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!