绑定跨度的内容 [英] Binding the content of a Span

查看:132
本文介绍了绑定跨度的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示文字的窗口。有两个部分的文字:第一个是固定的,而第二个需要是在窗口上声明的DependencyProperty的内容。



我认为使用包含两个Spans,其中第一个包含固定内容,第二个包含可变内容,但我无法在Span类中看到任何明显的内容,它们将允许我绑定到上述的DependencyProperty。



我目前使用两个并排堆叠的标签,但这很丑陋,如果我希望检索整个文本块的内容并不帮助我(正如我在显示工具提示时窗口太窄而无法显示整个文本块的事件)。

任何人都可以帮助我解决这个看似简单的问题吗?感谢。

解决方案

如果您使用的是.NET 4:

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

在.NET 4之前, Run Text 属性不是依赖项属性。


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.

解决方案

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.

这篇关于绑定跨度的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆