I am making a user control (view) that mimics windows explorer in detail view.
I use a TreeView control for the tree navigation (on the left) and a XamDataGrid for the details view of files (on the right).
I have created a context menu for the grid and it works great. However what I actually want is to have 2 context menus. One that relates to the grid, e.g. to include add file, folder and one that relates to the records (files/folders) e.g. to include rename, delete. How do I create a seperate context menu for records?
Thanks in advance for your help!
Got it to work sort of. I now have two context menus but the context menu for my records does nto fire my commands. Wrong Context?
<igDP:XamDataGrid.ContextMenu><!-- Grid Context Menu --> <ContextMenu> <MenuItem Command="{Binding AddNewCommand}" CommandParameter="Document" Header="New Document" /> <MenuItem Command="{Binding AddNewCommand}" CommandParameter="Folder" Header="New Folder" /> <MenuItem Command="{Binding ResetCommand}" Header="Refresh" /> </ContextMenu> </igDP:XamDataGrid.ContextMenu> <igDP:XamDataGrid.Resources> <ContextMenu x:Key="RecordContextMenu"><!-- Record Context Menu --> <MenuItem Command="{Binding DoubleClickItemCommand}" Header="Open" /> <MenuItem Command="{Binding EditCommand}" Header="Edit Metadata" /> <MenuItem Command="{Binding DeleteCommand}" Header="Delete" /> </ContextMenu> <Style TargetType="{x:Type igDP:DataRecordCellArea}"> <Setter Property="ContextMenu" Value="{DynamicResource RecordContextMenu}"></Setter> </Style>
</igDP:XamDataGrid.Resources>
Sorted! I'm on fire today! Context needed to be changed. Code below...
<igDP:XamDataGrid.Resources> <!-- Record Context Menu --> <ContextMenu x:Key="RecordContextMenu"> <MenuItem Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.DoubleClickItemCommand}" Header="Open" /> <MenuItem Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.EditCommand}" Header="Edit Metadata" /> <MenuItem Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}, Path=DataContext.DeleteCommand}" Header="Delete" /> </ContextMenu> <Style TargetType="{x:Type igDP:DataRecordCellArea}"> <Setter Property="ContextMenu" Value="{DynamicResource RecordContextMenu}"></Setter> </Style> </igDP:XamDataGrid.Resources>
Hi,
Glad to see you have this worked out on your own. Also from the thread I see this is going to be a very useful sample for our other user, if you were to take the time and upload it to the thread.
Thanks in advance.
I tried this exact code. When the command fires, the object it gets is null, so I don't know which row it applies to. How do I get around this?
Hello Barry,
Thank you for your post. I have been looking into it and I created a sample project for you with the functionality you want. Basically I bound the CommandParameter of the command to the PlacementTarget of the ContextMenu, which is the DataRecordCellArea. Once you get it as parameter of the Execute method of the command, you can use it to get the underlying object. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.