エディター(テキストボックス)があり、クリックされたボタンに基づいて異なるテキストをバインドしたいと思います。
ボタンのコマンドを使用して、編集したい文字列をcommandparameterを介して渡し、テキストボックスにバインドされている文字列を更新することができます。これは機能しますが、テキスト(コマンドパラメータを介して渡された)とテキストボックスのテキストの間にバインディングがないため、変更は保存されません。
私の質問は、ビューモデルから直接テキストボックスにアクセスせずに、このバインドを適切に実装するにはどうすればよいですか?
編集:それはおそらく私が達成しようとしていることは曖昧です。私はそれを少し明確にしようとします:
したがって、いくつかの異なるボタンがあるとしましょう。そのうちの1つをクリックすると、文字列がエディターのテキストボックスにバインドされ、後で変更して保存できます。
<Button Content="Edit query" Command="{Binding ShowQueryInEditorCommand}" CommandParameter="{Binding SomeSqlStringToBeEdited}"/>
<Button Content="Edit query" Command="{Binding ShowQueryInEditorCommand}" CommandParameter="{Binding SomeOtherSqlStringToBeEdited}"/>
これは、コマンドが実行するものです。
public void ShowQueryInEditor(object o)
{
string SqlStatementParam = o as string;
if (SqlStatementParam != null)
SQLStatement = SqlStatementParam;
}
そして、エディターのTextBox自体は次のようになります。
<TextBox Text="{Binding SQLStatement}">
ご覧のとおり、これはSQLStatement文字列を設定するだけなので非常に初歩的なものですが、それらの間にバインドがないため、変更をSomeSqlStringToBeEdited/SomeOtherSqlStringToBeEditedに反映することはできません。これは、ボタンがクリックされたときにその文字列をテキストボックスにバインドするために私が達成したいことです。