簡體   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