I've been trying to use MVVMLight's Event to Command to link my ViewModel's commands to events such as TextChanged's TextBox, for example. But Event to Command automatically assumes that the Command Parameter is the Event Args of TextChanged. I do not want this, what I need is to send the model as Command Parameter, like this:
<TextBox Grid.Column="1" Text="{Binding Valor, Mode=TwoWay, Converter={StaticResource CVTStringTODecimal}, UpdateSourceTrigger=PropertyChanged}" Background="LightGray">
<interact:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="TextChanged">
<core:InvokeCommandAction Command="{Binding ElementName=usr_Receita, Path=DataContext.ModificacaoAgendaReceita}"
CommandParameter="{Binding}"/>
</core:EventTriggerBehavior>
</interact:Interaction.Behaviors>
</TextBox>
ModificationAccountReceive is the name of the command associated with the following method, which has the parameter obj
as argument:
public void ModificarAgendaReceita(object obj)
{
var p_atual = (ModelAgendaReceita)obj;
var p_inicial = ListaAgendaReceitaInicial.FirstOrDefault(l => l.ID == p_atual.ID);
if (p_inicial != null) p_atual.Status = ModelAgendaReceita.ValidarAlteracao(p_inicial, p_atual);
}
Since the TextBox is inside a Listview, the CommandParameter="{Binding}"
should send the ModelAgendaReceita
, which is the model that feeds the ItemsSource of the ListView. The Event to Command keeps passing the TextChangedEventArgs as CommandParameter, and I need the Model.
Does anyone know a solution to this? All advice / help will be welcome!