/ / EventToCommand non funziona mai per me: wpf, vb.net, mvvm, mvvm-light

EventToCommand non funziona mai per me: wpf, vb.net, mvvm, mvvm-light

Sto tentando di cambiare il mio codice corrente e spostarlo verso un design MVVM.

Ho un controllo di griglia in quanto tale:

        <ctl:GridContainer x:Name="GridResponses" CellValueChanged="GridResponses_CellValueChanged">
.
.
.
</ctl:GridContainer>

con un pari come tale:

        Private Sub GridResponses_CellValueChanged(sender As Object, e As CellValueEventArgs)
If e.Column.FieldName = "PRIORITY" Then
.
.
.
End If
End Sub

ora sto spostando il codice sopra per usare MVVM Light e facendo quanto segue:

        <ctl:GridContainer DataContext="{Binding ResponsesDataView}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="CellValueChanged">
<cmd:EventToCommand Command="{Binding GridCellValueChangedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ctl:GridContainer>

e nel mio ViewModel ho il seguente RelayCommand dichiarato come segue:

        Private m_cmdGridCellValueChanged As RelayCommand(Of CellValueEventArgs)

.
.
.

m_cmdGridCellValueChanged = New RelayCommand(Of CellValueEventArgs) _
(Sub(e)
If e.Column.FieldName = "PRIORITY" Then
.
.
.
End If
End Sub)

e non esegue MAI! Ho anche provato a usare un RelayCommand senza parametro e ho provato a mostrare un MessageBox e questo non ha funzionato.

EventToCommand è limitato in termini di eventi specifici? Sto facendo qualcosa di sbagliato???

risposte:

1 per risposta № 1

In realtà il problema è vincolante. Stai cercando il comando in ResponsesDataView. devi attraversare per il DataContext della tua vista -

 <cmd:EventToCommand Command="{Binding DataContext.GridCellValueChangedCommand,
RelativeSource={RelativeSource FindAncestor,
AncestorType=UserControl}}"/>