Hi there,
In igDP:XamDataGrid.Resources, I added event setter for igDP:DataRecordPresenter, for example, <Style TargetType="{x:Type igDP:DataRecordPresenter}"> <EventSetter Event="MouseDoubleClick" Handler="myMouseDoubleClick" /> </Style>
But why this event doesn't get fired when I right click xamdatagrid?
If I use EventManager.RegisterClassHandler, it works. But since we have different forms with different grids, the registered event will affect all grids. That's why I hope the first method will work.
Thanks for help.
My two cents :
also make sure that event code is put in code behind class that is referenced in style file.
style file MyStyle.xaml:
<ResourceDictionary x:Class="SomeNamespaces.MyStyle"
x:ClassModifier="public"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"...
code behind MyStyle.xaml.cs :
namespace SomeNamespaces {public class MyStyle{
public void XamDataGrid_Loaded(object sender, RoutedEventArgs e) {
...
}}}
Hello TTran117,
I believe that if you set the style for the DataRedordPresenter in the Window.Resourses section and assign it some key for example x:Key=”clickStyle”, then you can apply it to the XamDataGrid where you want to handle the event like this:
<igDP:XamDataGrid.FieldLayoutSettings>
<igDP:FieldLayoutSettings DataRecordPresenterStyle="clickStyle" />
</igDP:XamDataGrid.FieldLayoutSettings>
I believe that this should apply the style to all records in the XamDataGrid no matter in which hierarchy they belong to. In the handler of the event you can gather all information for the clicked record, even when you do this with the right mouse button using the property DataRecord of the sender:
(sender as DataRecordPresenter).DataRecord.ToString();
If you have any further questions, please don’t hesitate to ask.
Hi,
Thanks so much for your reply. Now adding PreviewMouseDoubleClick in xamdatagrid works fine.
But if I add PreviewMouseRightButtonDown event handler in xamdatagrid, the active record is always null. How can I get the record I'm currently clicking?
Also if I added PreviewMouseRightButtonDown/Mousedoubleclick as event setter in xamdatagrid resource, it only worked for child record, but not for parent record (won't fire event).
Maybe I missed something?
Thanks!
I was looking into your issue and I tested it by adding your code in the XamDataGrid’s Resources section and the event fired as expected. In order to achieve the desired functionality for only one of the grids you can specify the event directly in the definition of the XamDataGrid or also you can try handle PreviewMouseDoubleClick event. If this doesn’t help in your scenario, could you please create a small sample where the issue is reproducible and send it back to me, so I can investigate this behavior.
Thanks in advance.