私のビューには、ボタンがあります。
ユーザーがこのボタンをクリックすると、ViewModel が TextBlock のコンテキストをデータベースに保存するようにします。
<StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock Text="{Binding FirstName}"/>
<TextBox Text="Save this text to the database."/>
<Button Content="Save" Command="{Binding SaveCommand}"/>
</StackPanel>
ただし、ViewModel の DelegateCommand では、「Save()」メソッドは引数を渡さないため、その時点でビューからデータを取得するにはどうすればよいでしょうか?
#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