私は今2日間頭をかきました。私は .NET を初めて使用しますが、20 を超える投稿と質問を読みました。私のコードは機能するはずです。いくつかは光を投げてください。
XAML:
<TextBox Grid.Column="3" Name="testgrid" Text="{Binding textsource, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
コードビハインド:
public MainWindow()
{
InitializeComponent();
textbind tb = new textbind();
tb.textsource = "one"; //one is displayed in the textbox.
testgrid.DataContext = tb;
}
と:
public class textbind : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
private string a=string.Empty;
public textbind()
{
}
public string textsource
{
get { return a; }
set
{
if (value != a)
{
a = value;
NotifyPropertyChanged(textsource);
}
}
}
}
プロパティの変更:
public class changevalue
{
//code doing things. this class is initialized by some other processes.
textbind tb1 = new textbind();
tb1.textsource = "two"; // no updates to two in the text box.
}
私が信じていたのは、textsource プロパティを変更するたびに、テキストボックスの変更が反映されるということですが、それは起こりません。誰か助けてください。
ありがとう。