WPF绑定到自己 [英] WPF Bind to itself

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

问题描述

我有一个WPF 窗口和某处有一个的ListView ,我绑定一个列表<字符串方式>

I've got a WPF Window, and somewhere there is a ListView where I bind a List<string> to.

现在在我的的ListView某处有一个文本框内容属性设置为 {结合}

Now somewhere in my ListView there is a TextBox and the Content property is set to {Binding}.

但是,这是简写。我怎样写完整绑定绑定到自己?

But this is the shorthand. How do I write the full binding to bind to itself?

{绑定路径=自} 不工作,也不做 {结合自} (后者是前者的快捷方式)。

{Binding Path=Self} doesn't work, neither does {Binding Self} (where the latter is a shortcut for the former).

推荐答案

简短的回答 {结合} 是的为结合自身快捷方式(在意义上的<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.data.relativesource.self.aspx\">RelativeSource.Self).相反, {结合} 相当于 {结合路径=} ,其结合到电流源

Short answer:{Binding} is not a shortcut for "binding to itself" (in the sense of RelativeSource.Self). Rather, {Binding} is equivalent to {Binding Path=.}, which binds to the current source.


要详细说明:一个绑定拥有的的和的路径的。你可以做一个结合至自身,例如,通过使用

To elaborate: A binding has a source and a path. You can do a "binding to itself", for example, by using

<myUIControl myProperty="{Binding RelativeSource={RelativeSource Self}, Path=x}" />

然而,设置的应用于控件本身,所以它会尝试访问属性 X上的UI控件的(而不是财产 X 当前数据上下文中)。从我了解如何你的问题,这是不是你想要的;特别是,它不是什么 {结合} 做: {结合} 保留,因为它是源(通常是的DataContext 一些父元素),并结合源本身(等同于路径= )。

This, however, sets the source to the control itself, so it will try to access property x of the UI control (rather than property x of the current data context). From how I understood your question, this is not what you want; in particular, it is not what {Binding} does: {Binding} keeps the source as it is (usually the DataContext of some parent element) and binds to the source itself (equivalent to Path=.).

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

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