나는 2 일 내 머리를 긁었다. .NET에 익숙하지는 않지만 20 개 이상의 게시물과 질문을 읽었으며 코드가 제대로 작동해야한다고 생각합니다. 일부는 빛을 던져주세요.INotifyProperty 값을 업데이트하지 않는 변경된 값
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 속성을 변경할 때마다 텍스트 상자의 변경 내용을 반영하지만 변경되지 않습니다. Soneone가 도와주세요.
감사합니다.
모드 = TwoWay 일 수 있습니까? –
특정 문제는 해결되지 않지만 실제로 NotifyPropertyChanged를 변경하여 'var handler = PropertyChanged; PropertyChanged가 테스트와 실행 사이에서 null로 갈 수있는 스레딩 문제를 피하려면 if (handler! = null) {handler (this, new PropertyChangedEventArgs (info));} –
[먼저 디버깅하는 방법 알아보기] (http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/debugging-data-bindings-in-a-wpf-or-silverlight-application.aspx) . –