2011-03-21 83 views
30

也許這是一個愚蠢的問題,但我找不到答案:在下面的xaml中CommandParameter綁定到什麼地方?或者一般來說,"{Binding}"是什麼意思?瞭解WPF綁定CommandParameter =「{綁定}」

<Button Command="{Binding DataContext.DeleteCommand, ElementName=List}" 
     CommandParameter="{Binding}"/> 

回答

49

{Binding ...}是一個MarkupExtension。
以其通常的形式,它需要一個像{Binding Path=someProperty, ...}(或其簡稱{Binding someProperty, ...})的路徑。
所以{Binding}中的路徑是空的,這意味着綁定綁定到綁定的任何源。如果你知道,這可能會更容易理解,即{Binding}實際上與{Binding DataContext,RelativeSource={RelativeSource Self}}相同。

所以在你的情況下,CommandParameter獲取Button的當前DataContext的值。