2
我有一個treeview綁定到一些屬性類型的Observable集合。有一個HierarchicalDataTemplate顯示樹狀視圖中的數據。現在我需要爲每個HierarchicalDataTemplate項目顯示特定的上下文菜單。Treeview上下文菜單命令沒有觸發
我用下面的XAML顯示上下文菜單:
<HierarchicalDataTemplate ItemsSource="{Binding Collections}">
<TextBlock Text="{Binding Path=Name}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="Create" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.AddCommand}" CommandParameter="{Binding}"/>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</HierarchicalDataTemplate>
這裏AddCommand被寫在被控制住綁定到該視圖模型.. 我能看到的上下文菜單,但是點擊菜單項時事件不會觸發。
請幫助..
這個力解決問題。 Command not firing still – Arihant 2012-02-27 11:32:27
如果AddCommand的屬性不在HierarchicalDataTemplate的綁定項目中,則不起作用。是這樣嗎? – Dror 2012-02-27 11:34:55
我更新了我的答案,請檢查它現在是否有效。 – Dror 2012-02-27 11:38:34