Mvvm如何使用TextChanged方法获取值txtNmItem

时间:2013-05-21 02:11:45

标签: windows-phone-8 mvvm-light

如何使用TextChanged方法获取值txtNmItem?

<TextBox Grid.Column="1" Name="txtNmItem" Background="#f3f3f3" BorderBrush="#f3f3f3" VerticalAlignment="top" Text="{Binding Path=sNmItem, Mode=TwoWay}">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="TextChanged">
                                                <cmd:EventToCommand Command="{Binding ElementName=ListaItem,Path=DataContext.SalvarCommand}" PassEventArgsToCommand="True"/>
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </TextBox>

视图模型

public RelayCommand<object> SalvarCommand { get { return new RelayCommand<object>(Salvar); } }

private async void Salvar(object e)
    {

1 个答案:

答案 0 :(得分:0)

我假设您需要TextChanged,因为绑定值仅在控制丢失焦点后才会更新。您需要在用户输入时更新您的媒体资源。

这可能会有所帮助:

查看

 <i:Interaction.Triggers><i:EventTrigger EventName="TextChanged">
        <cmd:EventToCommand Command="{Binding SalvarCommand}"
        CommandParameter="{Binding ElementName=sNmItem, Path=Text}/></i:EventTrigger></i:Interaction.Triggers>

视图模型

public ICommand SalvarCommand
{
  get {
    return new RelayCommand<string>((param) =>
    {
      ...
    });
  }
}