이에서 INotifyPropertyChanged를 구현 뒤에 코드가 될 것이다 :
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _fileName;
/// <summary>
/// Get/Set the FileName property. Raises property changed event.
/// </summary>
public string FileName
{
get { return _fileName; }
set
{
if (_fileName != value)
{
_fileName = value;
RaisePropertyChanged("FileName");
}
}
}
public MainWindow()
{
DataContext = this;
FileName = "Testing.txt";
}
private void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
이 재산에 결합하여 XAML 것 :
<TextBlock Text="{Binding FileName}" />
편집 :
추가 의 DataContext = 이; 저는 일반적으로 코드 뒤에 바인딩하지 않습니다 (MVVM 사용).
관련 코드 및 XAML을 게시하십시오. –