相关疑难解决方法(0)

数据绑定链

我正在尝试按照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)

c# data-binding wpf

2
推荐指数
1
解决办法
1685
查看次数

标签 统计

c# ×1

data-binding ×1

wpf ×1