0
同樣的問題:WPF ContextMenu with ItemsSource - how to bind to Command in each item?綁定到文本菜單用的ItemSource
我試過如下實施,但沒有骰子。
目前在我的XAML:
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Woooo" Command="{Binding ReassignFileCommand}" />
</ContextMenu>
</DataGrid.ContextMenu>
需要改變,以(解決方案):
<Setter Property="Command" Value="{Binding Path=DataContext.ReassignFileCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" />
你是正確的,但結合的datacontext文本菜單的我嘗試過: set =「{」Binding ReassignFileCommand,RelativeSource = {RelativeSource Mode = FindAncestor,AncestorType = {x:Type DataGrid},AncestorLevel = 1}} /> 也試過ContextMenu as x:類型 仍然得到: BindingExpression路徑錯誤:'Reas對象 ' '' 數據網格 '(名稱= 'ui_dtgAgreements')」 – 2012-04-11 22:12:51
' 上沒有發現屬性' signFileCommand應當'值=「{結合DataContext.ReassignFileCommand,的RelativeSource = {的RelativeSource模式= FindAncestor,AncestorType = {X:類型數據網格},AncestorLevel = 1}}「' – Nikolay 2012-04-12 05:55:13