フォームに String プロパティがあるとします (フォームは INotifyPropertyChanged を実装していません)。また、BindingSource を作成し、その DataSource をフォームに設定しました。次に、テキスト ボックスをフォームの String プロパティにバインドします (BindingSource を使用して間接的に)。
質問 1: 実行時にテキスト ボックスの値を変更するときに、String プロパティのセッターでブレークポイントにヒットしないのはなぜですか? コントロールを String プロパティにバインドすると、この方向 (GUI -> メンバー データ) の更新が自動的に行われるようになると考えました。
質問 2: GUI 以外の何かが String プロパティを変更したときに、他の方向 (メンバー データ -> GUI) で更新をトリガーするにはどうすればよいですか? INotifyPropertyChanged インターフェイスを実装して NotifyPropertyChanged をセッターに追加したくありません。BindingSource の ResetBindings を使用することで、少なくともこれを手動でトリガーできると思いました
public partial class Form1 : Form
{
private String m_blah;
public String Blah
{
get
{
return m_blah;
}
set
{
m_blah = value;
}
}
public Form1()
{
InitializeComponent();
textBox1.DataBindings.Add(new Binding("Text", bindingSource1, "Blah",true,DataSourceUpdateMode.OnValidation));
}
private void button1_Click(object sender, EventArgs e)
{
Blah = "Clicked!";
this.bindingSource1.ResetBindings(false); //expecting the GUI to update and say "Clicked!"
}
}