I'm new to C# and WPF, so please don't roast me to hard :)
I have an ObservableCollection<> of many objects which I show in a ListBox by using
MyListBox.ItemsSource = MyObservableCollection;
The goal now is to change the selected item, so what I'm doing is the following:
MyClass selectedObject = MyListBox.SelectedItem as MyClass;
Now I can just say something like selectedObject.Name = "Something"
and of cause the value of selectedObject.Name gets changed. But to my surprise the value gets also changed in my original ObservabalCollection object ("MyObservableCollection").
This is exactly what I want, but tbh I don't understand why and how this works. How is selectedObject connected to the original object inside the ObservableCollection?
Further on im passing selectedObject as an argument to a new window, for doing the editing inside this new window:
EditObject editObject = new EditObject(selectedObject);
Even in the new window I can just asign new values to selectedObject and they get changed in my ObservableCollection too.
Can someone explain this behavior to me? :)
Thank you!