Comment transmettre les informations de View à ViewModel avec DelegateCommand?

De mon point de Vue, j'ai un bouton.

Lorsque l'utilisateur clique sur ce bouton, je veux avoir le ViewModel enregistrer le contexte de la TextBlock dans la base de données.

<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
    <TextBlock Text="{Binding FirstName}"/>
    <TextBox Text="Save this text to the database."/>
    <Button Content="Save" Command="{Binding SaveCommand}"/>
</StackPanel>

Cependant, dans mon DelegateCommand dans mon ViewModel, le "Save()" méthode ne passe pas d'arguments, alors comment puis-je obtenir les données à partir de la vue à ce point?

#region DelegateCommand: Save
private DelegateCommand saveCommand;

public ICommand SaveCommand
{
    get
    {
        if (saveCommand == null)
        {
            saveCommand = new DelegateCommand(Save, CanSave);
        }
        return saveCommand;
    }
}

private void Save()
{
    TextBox textBox = ......how do I get the value of the view's textbox from here?....
}

private bool CanSave()
{
    return true;
}
#endregion

source d'informationauteur Edward Tanguay | 2009-05-28