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
355
MVVM and EventTrigger
posted

I'm trying to relay the Drop event to a command.  Why doesn't the following work...

<Border Background="#f7f7f7" BorderBrush="#ccc" BorderThickness="1" Margin="2" Padding="4" Cursor="SizeAll">

                                        <ig:DragDropManager.DragSource>

                                            <ig:DragSource IsDraggable="True">

                                                <i:Interaction.Triggers>

                                                    <i:EventTrigger EventName="Drop">

                                                        <i:InvokeCommandAction Command="{Binding DataContext.AddChartCommand, ElementName=ReportDocumentView}"/>

                                                    </i:EventTrigger>

                                                </i:Interaction.Triggers>

                                            </ig:DragSource>

                                        </ig:DragDropManager.DragSource>

 

                                        <TextBlock Text="{Binding DisplayName}"/>

                                    </Border>

 

Is it because DragSource uses a regular event instead of a routedevent?  Is that a requirement for EventTrigger?  Also, just fyi, I tested the InvokeCommand code on a button's click event and it worked fine.  It just doesn't work when attached to the DragSource.

  • 355
    posted

    Ok, that was painful but I figured it out.  Binding inside the DragSource EventTrigger wouldn't work whatsoever (it always returned null for any binding).  The key was to use the new x:Reference binding in .Net 4.0...

    <i:InvokeCommandAction Command="{Binding Source={x:Reference ReportDocumentView}, Path=DataContext.AddChartCommand}"/>