I am trying to create a simple TreeView which will represent my applications data directory, however I found that when trying to implement a folder rename option that I could not bind my command paramater on the context menu to a StackPanel.
Code:
<Grid>
<Label Content="{Binding Path=FolderName}">
<Label.ContextMenu>
<ContextMenu>
<MenuItem Header="Rename Folder" Command="{Binding Path=ToggleControlVisability}" CommandParameter="{Binding ElementName=FolderNameEditor}"></MenuItem>
<MenuItem Header="Delete Folder" Command="{Binding Path=DeleteFolder}" CommandParameter="{Binding Path=FolderInformation}"></MenuItem>
</ContextMenu>
</Label.ContextMenu>
</Label>
<StackPanel Name="FolderNameEditor" Orientation="Horizontal" Visibility="Hidden">
<TextBox Name="EditFolderName" Text="{Binding Path=FolderName}"></TextBox>
<Button Content="Ok" Command="{Binding Path=ToggleControlVisability}" CommandParameter="{Binding ElementName=EditFolderName}"></Button>
</StackPanel>
</Grid>
The problem seems to be the hierachy, is there some way I can use a relative source to bind the rename folder menu item command paramater to the stack panel containing the editor elements?
Thanks,
Alex.
The MenuItems aren’t part of the visual tree, so you must add an explicit “CommandTarget” binding to the command listener (or any descendant).