Hi,
I want to add two different context menus for a single grid (for hierarchical data). I have two different layouts in xamdatagrid. For each layout I want to have a context menu. My xaml code is as below:
<DataPresenter:XamDataGrid x:Name="grdMilestone" DataSource="{Binding Source={StaticResource odpObjectDataProvider1}}"
Margin="293.675,84.287,-116.079,0" VerticalAlignment="Top"
ContextMenu="{StaticResource ctxMilestoneMenu}" >
<DataPresenter:XamDataGrid.FieldLayouts>
<DataPresenter:FieldLayout Key="master">
<DataPresenter:FieldLayout.Fields>
<DataPresenter:Field Name="Milestone" Label="Milestone" >
<DataPresenter:Field.Settings>
<DataPresenter:FieldSettings CellMinWidth="210" AllowEdit="False"/>
</DataPresenter:Field.Settings>
</DataPresenter:Field>
<DataPresenter:Field Name="DueDate" Label="Due Date" >
<DataPresenter:FieldSettings CellMinWidth="60" AllowEdit="False" />
<DataPresenter:Field Name="Status" Label="Status">
<DataPresenter:FieldSettings CellMinWidth="100" AllowEdit="False"/>
<DataPresenter:Field Name="Deliverables" Label="Deliverables">
<DataPresenter:FieldSettings CellMinWidth="160" AllowEdit="False" />
</DataPresenter:FieldLayout.Fields>
</DataPresenter:FieldLayout>
<DataPresenter:FieldLayout Key="detail">
<DataPresenter:Field Name="Task" Label="Task" >
<DataPresenter:FieldSettings AllowEdit="False"/>
<DataPresenter:Field Name="CustomerInvolved" Label="Customer Involved" >
<DataPresenter:Field Name="Email" Label="E-mail Reference" >
<DataPresenter:Field Name="OwnerStatus" Label="Owner Status" >
<DataPresenter:FieldSettings AllowEdit="False" />
<DataPresenter:Field Name="IsPrivate" Label="Is Private" >
</DataPresenter:XamDataGrid.FieldLayouts>
</DataPresenter:XamDataGrid>
Hello,
You can try a similar approach like the one here.
Hi Alex,
I read the article in the link provided by you. It did not help me.
In my screen I have two layouts which display hierarchical data,
(<DataPresenter:FieldLayout Key="master"> && DataPresenter:FieldLayout Key="details">)
I have to display separate context menu for each one of them. Please give me more details .
Xamgrid is displaying the Records in hierarchical order so master and child grids are shown. I want to create separate context menu for each of them
So, let's say you are using the ContextMenuOpening event. I am not sure on which element you want to use that, so I am assuming the CellValuePresenter. Handling this event on the CellValuePresenter, you will have access to the record.
Record r = (sender as CellValuePresenter).Record;
The record exposes a FieldLayout property, which will return its field layout. Knowing the field layout, you can check its Key property and see if it is a master or details.
Moreover, you can create a DataTrigger and do the same, like so:
<Style TargetType="{x:Type igDP:CellValuePresenter}">
<Style.Triggers>
<DataTrigger Binding="{Binding FieldLayout.Key}" Value="master">
<Setter Property="ContextMenu" Value="{StaticResource myMasterContextMenu}"/>
</DataTrigger>
</Style.Triggers>
</Style>
I have given my code in the bginning of the post. I tried to access the Record using your code but all the time r value is null. I want the context menu to appear on grid(Please refer my code). The code you have given is not working for me.
Another customer has successfully created such a context menu in this thread following the blog post. I am not sure why it is not working for you, and if you still have problems with that please attach a sample so that we can look into it.