确切地< Expander Header =" {Binding}">会做什么?做? [英] What does exactly <Expander Header="{Binding}"> do?

查看:77
本文介绍了确切地< Expander Header =" {Binding}">会做什么?做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建简单的自定义扩展器时,我遇到了IT内的项目无法绑定的问题.我在此链接上找到了解决方法:

While creating a simple custom expander, I encountered the problem where items inside IT wouldn't bind. I found the fix on this link:

http://codeoverload .wordpress.com/2012/03/04/wpf-expander-headertemplates-dont-forget-the-binding/

碰巧会处理同样的问题,但是我从中了解到的是运气不错,不太确定为什么会起作用; D"

Which happens to treat that exact same issue, however what I understand from it is "found this by luck, not really sure why it worked ;D"

我现在的问题是:为什么添加Header = {Binding}可以解决此问题.确实,从事实绑定实际上是行不通的,这似乎是由于DataContext引起的,但我不知道如何解决该问题.

My question being now: why does adding Header={Binding} fixes the issue. Indeed from the fact binding wouldn't work, it seems it's due to the DataContext, but I don't see how this should fix it.

感谢您的解释;希望这不是重复的>.<

Thanks for explaining; hopefully this isn't a duplicate >.<

推荐答案

来自

获取或设置用于每个控件的标头的数据.

Gets or sets the data used for the header of each control.

该对象是对DataContext或纯文本或任何其他内容的绑定.

That object being a binding against the DataContext, or plain text, or whatever.

我敢打赌,该实现看似看该值是否为文本,如果是,则将其扔到默认的标头模板中,该模板可能很简单

I'd bet the implementation looks to see if the value is text, and if so, throws it into the default header template which could be something as simple as

<TextBlock Text="{Binding}" />

如果为标头声明模板,则DataContext将是您分配给Header属性的任何内容.显然,扩展器的DataContext不会自动流到标题模板.

If you declare a template for the header, the DataContext will be whatever you assign to the Header property. The DataContext of the Expander doesn't flow automatically to the header template, apparently.

这篇关于确切地&lt; Expander Header =&quot; {Binding}&quot;&gt;会做什么?做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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