Mvvmlight Event to Command using Model for Command Parameter

Asked

Viewed 29 times

1

I’ve been trying to use Mvvmlight’s Event to Command to link my Viewmodel commands to events like Textchanged from Textbox, for example. But Event to Command automatically assumes that the Command Parameter is the Event Args of Textchanged. I don’t 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>

Modified gendered is the name of the command associated with the following method, which has the parameter obj as an 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 Textbox is inside a Listview, the CommandParameter="{Binding}" should send the ModelAgendaReceita, which is the model that powers Itemssource from Listview. Event to Command keeps passing Textchangedeventargs as Commandparameter, and I need Model.

Does anyone know a solution to this? Any advice/help will be welcome!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.