我試圖將ContextMenu
項的commandParamater
綁定到窗體上的另一個元素,但不管我嘗試的是什麼commandParamater
始終是null
。ContextMenu CommandParamater綁定?
有人可以告訴我如何正確綁定我的上下文菜單項的commandParamater
?
我有什麼:
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Files}">
<Grid>
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="Rename Folder"
Command="{Binding Path=ToggleControlVisability}"
CommandTarget="{Binding ElementName=FolderEditor}"
CommandParameter="{Binding ElementName=FolderEditor}">
</MenuItem>
</ContextMenu>
</Grid.ContextMenu>
<Label Content="{Binding Path=FolderName}"></Label>
<StackPanel Name="FolderEditor" Orientation="Horizontal"
Visibility="Hidden">
<TextBox Text="{Binding Path=FolderName}"></TextBox>
</StackPanel>
</Grid>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
可能重複在文本菜單從菜單項綁定](http://stackoverflow.com/questions/1013558/elementname-binding-from-menuitem-in-contextmenu) – CodeNaked