C# WPF Tutorial #13 - ObservableCollection with ListView
HTML-код
- Опубликовано: 7 июн 2024
- Learning how to use ObservableCollection as the ListView's Item source, allowing us to use a single collection in our code and have the UI update itself automatically when the list is updated!
Happy Coding!
Chapters:
0:00 Setup
0:54 ItemsSource Property Binding
1:24 ObservableCollection
3:52 Adding to the Collection
4:22 Deleting from the Collection
7:06 Clearing the Collection
7:22 Recap
7:44 Next Up - Наука
This was the best WPF Tutorial series I ever watched. Everything was so easy to follow.
Thanks so much, I'm really glad to hear that! I have a lot more topics to cover, let me know if you have any questions or suggestions!
@@KampaPlays Um yeah I think a Navigation video would be great.
@@Jayammo2 Great idea, I will work this in, thanks!
Fully agree. I did not finish the tutorial and it is the best playlist by far
Using debugger effectively helps a lot for learning, thank you a lot!
Great to hear!
This whole serie is amazing. Keep up the good work!
Thank you so much!! Lots more to do!
🤩🤩 Yes!! This is what I wanted to know! You always present the core stuff concisely! It seems that I can apply this lesson to my toy project which has DataGrid with ItemSource. The logic and principle may be same with List. ☺☺ Thank you very much as always!! 😄😄
Thank you!! You can use List as an ItemSource binding with DataGrid but it will not automatically notify on all collection operations like an ObservableCollection will. You can use ObservableCollection with DataGrid, though!
You did good job~~! You raised me up in C# world.
Awesome to hear, thank you.
BEST Videos! Thank you. They really help!!
Thanks so much, I'm glad!!
really great series, dont stop
Thank you, still more to come!
Thanks!
Wow, thank you so much! Really appreciate that.
Love your videos. So far the clearest explanation of data binding, ObservableCollections, etc. that I have found.
In this exercise, is there a disadvantage to initializing the collection when it is declared (instead of in the constructor)?
private ObservableCollection entries = new();
Thank you so much, I really appreciate that!
In this case, I don't think there are any real disadvantages to doing that. Basically either way, you are creating the collection on class instantiation (generally its safe to assume the constructor will run first, anyway). I do this occasionally, depending on the object's purpose/scope.
I wouldn't get into a habit of always or blindly initializing in the declaration though, because often times you will end up creating objects well before you need them, spending memory unnecessarily, and increasing the time it takes to create your class. Creating the objects when you need them (lazy initialization) can increase performance a good bit at scale.
Hope this helps!
Don't you think about to make a course for Udemy? I'm not english speaker but can understand and you make it so easy to learn the concepts.
Btw, thanks so much for this videos!
Thanks for the video. Really helpful. I have a question here we are using binding but we are taking text box entry (That we are adding on button click)from GUI i.e., It we are not running independently right. Please correct me if i am wrong.
Correct - trying to sprinkle in a bit of functionality over time as to not overwhelm -- developing the UI truly independently would use all bindings, and likely incorporate the MVVM pattern in doing so.
thanks
You're welcome!
I am programing in React a lot and there we have useState hook. UseState automaticlly refresh your view when it has been changed. Obsevarble collection I understand works similar. Correct me if I think wrong.
Yes! I didn't do any React until I had already worked in WPF, and I thought the same thing when I saw UseState!
I checked like 3 times that I did it exactly as you, but my ListView stays empty after manually adding items `Entries.Add("Test")` in the Constructor of the binding class.
Hm. Make sure you have set your datacontext, InitializeComponent is called first, and double check your spelling/capitalization on your binding. These are common things that might be your issue.
Thank you....
Glad to help!