繁体   English   中英

WPF:如何绑定到另一个控件绑定的属性?

[英]WPF: How to bind to a property of another's control binding?

我正在使用WPF和MVVM创建表单。

在那里,我将视图及其数据源绑定到了ViewModel对象。 大。

在我的xaml中,我有一个ItemsControl,其ItemSource绑定到ViewModel.MyCollectionOfFoo。

对于此集合中的每个Foo对象,我都将创建一个具有对此foo对象的绑定的控件,但是我还需要将Command绑定到其中的每个对象。

此命令是我的ViewModel对象的属性(女巫是视图的数据源)。

由于我在ItemsControl中,因此如何获取对ViewModel.DoSomethingCommand的引用?

就像绑定到另一个控件的绑定属性...

谢谢,

安德烈·卡鲁奇(AndréCarlucci)

<... Command="{Binding Path=DataContext.CommandPropertyOfYourViewModel, 
                       RelativeSource={RelativeSource FindAncestor, 
                                                      AncestorType={x:Type Window}}}">

这将使用Window的DataContext作为绑定源,而不是当前的DataContext。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM