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!
Hi Stefan, I downloaded that example (and other similar ones) and it works, HOWEVER, I also need the command's CanExecute() to work based on the grid item the user right clicked on. The command's Execute method does get the correct grid row data item, however, the CanExecute()'s parameter is null.
What is the recommended way to make this work?
Thanks.
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.
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?
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.
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>