私はWPF ViewModelを持っています
class MainWindowViewModel : INotifyPropertyChanged
{
private string _sql;
public string Sql
{
get { return _sql; }
set
{
if (value == _sql) return;
OnPropertyChanged("Sql");
_sql = value;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
TextBox を含む XAML ビューもあります
<Window.Resources>
<HbmSchemaExporter:MainWindowViewModel x:Key="viewModel"/>
</Window.Resources>
....
<TextBox Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Source={StaticResource ResourceKey=viewModel}, Path=Sql,Mode=OneWay}"/>
コードビハインド
private MainWindowViewModel ViewModel
{
get { return Resources["viewModel"] as MainWindowViewModel; }
}
問題は、コード内でviewModel.Sql = SOMETHING
テキスト ボックスが更新されないことです。デバッガーはプロパティに正しい値を表示しますが、テキスト ボックスは空白のままです。
また、バインディングを変更しようとしましたTwoWay
が、テキストボックスに入力した値でプロパティを上書きすることしかできません。これは本当に望んでいないことです (実際にはまだ読み取り専用にする必要がありますが、現在は範囲)。
プログラムでプロパティを更新した後、テキスト ボックスを更新するにはどうすればよいですか?
このアプリケーションは基本的に、これを読んだ後に書いている NHibernate DDL ジェネレーターです。「Generate SQL」ボタンを押すと、DB で実行するコードが表示されます。