我正在尝试按照DataBinding
Property -> DependencyProperty -> Property
Run Code Online (Sandbox Code Playgroud)
但我有麻烦.例如,我们有两个属性实现INotifyPropertyChanged的简单类:
public class MyClass : INotifyPropertyChanged
{
private string _num1;
public string Num1
{
get { return _num1; }
set
{
_num1 = value;
OnPropertyChanged("Num1");
}
}
private string _num2;
public string Num2
{
get { return _num2; }
set
{
_num2 = value;
OnPropertyChanged("Num2");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(e));
}
}
Run Code Online (Sandbox Code Playgroud)
并且在xaml中声明了TextBlock:
<TextBlock Name="tb" FontSize="20" Foreground="Red" …
Run Code Online (Sandbox Code Playgroud)