MVVM and EventTrigger

This post has 1 Reply | 1 Follower

gbjorgan
Points 355
Replied On: Sat, Jul 30 2011 2:08 PM

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.

  • Post Points: 5
gbjorgan
Points 355
Replied On: Sun, Jul 31 2011 1:05 AM

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}"/>

  • Post Points: 5
Page 1 of 1 (2 items) | RSS