Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
330
Assigning DragSource to a DataRecordPresenter
posted

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

Parents Reply Children
No Data