简体   繁体   English

WPF控件绑定问题

[英]WPF control binding Issue

I have issued with WPF binding, I have ListBox binding to persons ObservableCollection with Textbox as DataTemplate that shows person, I want the Background of TextBox change from red to green if it red, and from green to red if it green, It changes but the ListBox doesn't show the changes, I have Raise the ObservableCollection but it's not work. 我已经发布了WPF绑定,我将ListBox绑定到人ObservableCollection,并且TextBox作为显示人的DataTemplate,我希望TextBox的背景从红色变为绿色,如果从红色变为绿色,从绿色变为红色,但是ListBox没有显示更改,我已经提出了ObservableCollection,但是它不起作用。

I have created a small new project please download HERE , and check what I miss. 我创建了一个新的小项目,请在这里下载,然后检查我想念的内容。

After run the application type person Id in textbox (for example 1) and press the change color button, the color will change but the listbox dose not respond for that change. 在文本框中运行应用程序类型人员ID(例如1)并按更改颜色按钮后,颜色将更改,但列表框对此更改不响应。

Thanks in advance 提前致谢

You should implement INotifyPropertyChanged interface also in People class: 您还应该在People类中实现INotifyPropertyChanged接口:

public class People : INotifyPropertyChanged
{
    public int PersonID { get; set; }

    private string _fullName;
    public string FullName
    {
        get { return _fullName; }
        set { _fullName = value; OnPropertyChanged("FullName"); }
    }

    private bool _Status;
    public bool Status
    {
        get { return _Status; }
        set { _Status = value; OnPropertyChanged("Status"); }
    }

    private SolidColorBrush _statusColor;
    public SolidColorBrush StatusColor
    {
        get { return _statusColor; }
        set { _statusColor = value; OnPropertyChanged("StatusColor"); }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void OnPropertyChanged(string name)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(name));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM