Hi Guys,
I'm trying to assign a (DragDropManager) DragSource property to the DataRecordPresenters in a XamDataGrid. I do this in a Handler of the Loaded Event like this:
<igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:DataRecordPresenter}"> <EventSetter Event="igDP:DataRecordPresenter.PreviewMouseLeftButtonDown" Handler="DataRecordPresenter_PreviewMouseLeftButtonDown" /> <EventSetter Event="Loaded" Handler="OnDataRecordPresenterLoad" /> </Style> </igDP:XamDataGrid.Resources>
And the Handler:
void OnDataRecordPresenterLoad(object sender, RoutedEventArgs e) { var drp = sender as DataRecordPresenter; if (drp == null) return; var ds = new DragSource() { DataObject = drp.DataContext, IsDraggable = true, DragChannels = new ObservableCollection<string>() { "TemplateFieldChannel" }, DragTemplate = this.TryFindResource("TemplateFieldDragTemplate") as DataTemplate }; ds.Drop += TemplateFieldChannel_Drop; ds.DragStart += TemplateFieldChannel_DragStart; DragDropManager.SetDragSource(drp, ds); }
The problem is that the Drop and DragStart events are not fired, unless i interrupt the process by placing a break point in the
DataRecordPresenter_PreviewMouseLeftButtonDown
Method. So in the following code:
void DataRecordPresenter_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { int i = 1; //Breakpoint 1 } private void TemplateFieldChannel_DragStart(object sender, Infragistics.DragDrop.DragDropStartEventArgs e) { int i = 2; //Breakpoint 2 } private void TemplateFieldChannel_Drop(object sender, Infragistics.DragDrop.DropEventArgs e) { int i = 3; //Breakpoint 3 }
If I have a break point in the "PreviewMouseLeftButtonDown", then the The DragStart and Drop Events are also fired. If I don't interrupt the Thread by placing a brake point in the Mouse Down event handler, the other two are not fired.
I suppose this is some kind of race condition. Any ideas on how to solve this issue?
Regards,
George
Hello George,
I am glad that you have managed to solve your issue.
I found it out!!!
The problem occures because of some other setting:
CellClickAction="SelectRecord"
in the FieldSettings of the XamDataGrid. If this parameter has the give value, the Drag-Events do not fire. If the value is defalt - everything works :)
Hi Yonko,
Thank you for your answer! Krasimier assigns the DragSource to a ContentPresenter named "PART_RecordContentSite" inside the DataRecordPresenter via Style. To do so in the XAML, one must override the whole ControlTemplate of the DataRecordPresenter. The following code should do exactly the same (theoretically), but in the code behind:
void OnDataRecordPresenterLoad(object sender, RoutedEventArgs e) { var drp = sender as DataRecordPresenter; var presenter = XamDataGridEditorStyles.FindChild<ContentPresenter>(drp, "PART_RecordContentSite"); if (presenter == null) return; var ds = new DragSource() { DataObject = drp.DataContext, IsDraggable = true, DragChannels = new ObservableCollection<string>() { "TemplateFieldChannel" }, DragTemplate = this.TryFindResource("TemplateFieldDragTemplate") as DataTemplate }; ds.Drop += new System.EventHandler<Infragistics.DragDrop.DropEventArgs>(this.TemplateFieldChannel_Drop);// TemplateFieldChannel_Drop; ds.DragStart += new System.EventHandler<Infragistics.DragDrop.DragDropStartEventArgs>(this.TemplateFieldChannel_DragStart); //TemplateFieldChannel_DragStart; DragDropManager.SetDragSource(presenter, ds); }
However the DragStarted is not fired as described in my first post.
So In this case my question would be: Is there no way to assign the DragSource Property without overwriting the whole ControlTemplate?
I have been looking into your post and I can suggest you look into the following forum thread where Krasimir has provided a solution on how to set the DataRecordPresenter as DragSource :
http://es.infragistics.com/community/forums/t/72874.aspx
I have tested the provided code and the ‘DragStart’ event is fired after the ‘PreviewMouseLeftButtonDown’ event .
If you need any further assistance on this matter. Please attach a sample application where your issue occurs.