0

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.

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.

Thanks in advance

1 Answer 1

1

You should implement INotifyPropertyChanged interface also in People class:

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));
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thaaaaaaaank you, I have spent about 5 hour in this issue, now with your help it works, really I thank you so so so much:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.