日期:2014-05-16  浏览次数:21258 次

WPF数据双向绑定问题
//Part1 begin
public class UserResource : INotifyPropertyChanged
    {
        private string _userName;

        public int ID { get; set; }
        public string UserName
        {
            get
            {
                return _userName;
            }
            set
            {
                _userName = value;
                OnChangedProperties(value);
            }
        }

        public UserResource()
        {

        }

        public UserResource(int ID, string userName)
        {
            this.ID = ID;
            this.UserName = userName;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnChangedProperties(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
//Part1 end

//Part2 begin
/// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        public static UserResource user = new UserResource(500, "ttest");

        private void btRefresh_Click(object sender, RoutedEventArgs e)
        {
      &n