MVVM and EventTrigger

This post has 1 Reply | 1 Follower

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:DragSource IsDraggable="True">


                                                    <i:EventTrigger EventName="Drop">

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






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



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
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