C# WPF Tutorial #8 - Data Bindings using INotifyPropertyChanged

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ม.ค. 2025

ความคิดเห็น •

  • @o0ODigoO0o97
    @o0ODigoO0o97 6 หลายเดือนก่อน +12

    I usually do not stop to comment videos at all, but I must say it, this is one of the best tutorials I've watched in 17 years I've been in this platform.
    Magnificent, so to speak.

  • @thomasmunguya2207
    @thomasmunguya2207 10 หลายเดือนก่อน +8

    I love how you not only show what to do but also the best way to do it. There are so many tutorials out there which just show how to do something without taking into consideration the best way to do it, or let me say without taking into consideration best practices. The best part for me in this tutorial is how you made sure that we are reusing code and taking maintainability into consideration by making the OnPropertyChanged method get the calling member name by itself.😅 By the way, I just learned about the CallingMemberNameAttribute right from this tutorial. Keep it up.👍

    • @KampaPlays
      @KampaPlays  9 หลายเดือนก่อน

      Thanks! I like that one too! C# has a lot of cool tricks like that (sometimes dangerous though!)

  • @manibaghdadi725
    @manibaghdadi725 9 หลายเดือนก่อน +4

    Literally the best wpf tutorial on the internet. I love it 🔥

    • @KampaPlays
      @KampaPlays  8 หลายเดือนก่อน +1

      Thanks so much!

  • @ahshch
    @ahshch 2 หลายเดือนก่อน +1

    This is the only video on whole youtube that explains the data binding perfectly. MVVM is very easy to understand if you know what is data binding and this video clearly explains it.

  • @demolishunDOTcom
    @demolishunDOTcom 25 วันที่ผ่านมา

    Holy crap dude! You are the BOSS!!! Binding was driving me to insanity! Thank you!

  • @AntonioCorneal
    @AntonioCorneal 2 หลายเดือนก่อน +1

    Maaaannn I've been trying to grasp that relationship between bindings and the properties for like a year on and off😅 You gave the perfect simple example for it to make sense! Thank you!

  • @edinetgrunhed6000
    @edinetgrunhed6000 ปีที่แล้ว +3

    it explain more simple than the books I've read, more concise and direct to the point explaination

  • @MatthiasS-jp5uu
    @MatthiasS-jp5uu 2 หลายเดือนก่อน

    god im so happy i found this video, i started with wpf and i was lost from the beginning, some of my co workers even sayed that if you make a grave mistake its easyer to start fresh. but now everything is starting to make sense. thanks for that playlist your a Hero.

  • @RaqiGirl
    @RaqiGirl 10 หลายเดือนก่อน +2

    Here I am again. Thirty-five years ago I went to college to learn all I could about programming. We were just starting to talk about object-oriented programming at the time and trying to learn the basics. Thirteen years ago I retired and went on to other things, such as traveling N. America in an RV. Recently I've wanted to write some code to watch our investments while we play here in Panama and at seventy-five have decided to "dust off the brain" and start learning a current, object-oriented language. After a few months of looking around I liked what I saw in C# and have begun learning. After looking at some other teachers and their tutorials I liked what I saw with @KampaPlays. I just hope now that I've found a teacher that you are able to keep up with me! 😁

    • @KampaPlays
      @KampaPlays  10 หลายเดือนก่อน +1

      This is so great. It sounds like you are living the most out life! C# is a great OO language. It is extremely versatile, and while it has great high level features like garbage collection, it can also get about as low level as you want it to, without getting into assembly. Happy coding!

  • @MrSharksk
    @MrSharksk หลายเดือนก่อน

    Mannn !, what an explanation , data bindings look so much easier right now for me, thank you !!

  • @qwerty3000
    @qwerty3000 ปีที่แล้ว +2

    Databindings used to confuse me, but you've just made it so simple to understand. Big ups, man!

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว +1

      Awesome!! Glad to help!

  • @wtsharpproductions
    @wtsharpproductions 8 หลายเดือนก่อน +2

    A literal, genius and expert on code. Definitely understands what's going on 'prior to' and during 'runtime' ... No cap given. And, I've watched a lot of C++/C# tutorials prior to this...
    "The instruction is truly ABOVE par here."
    Thank you, Brother! @Kampa Plays ...Let's GO ! VIBES !! 🔥🔥🔥

    • @KampaPlays
      @KampaPlays  8 หลายเดือนก่อน +1

      Thank you, really appreciate that!!

  • @junulee3584
    @junulee3584 ปีที่แล้ว +8

    Best WPF tutorial among I've found so far. Thank you so much.

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Great, thank you!!!

    • @dzendys_
      @dzendys_ ปีที่แล้ว

      I agreee, I was totally lost, when i saw OnPropertyChanged() in someone's other tutorial.This video has helped me to finally understand it well and how it works in the background. Not the classical: "okay, so this does that and when does this happen, this will be called and this will happen". Thanks

  • @mumk
    @mumk 2 หลายเดือนก่อน

    Crazy stuffs, this is exactly what I need to improve my small program, it was invaluable and I cannot express my gratitude enough!!!! Thank you!

  • @flaric590
    @flaric590 10 หลายเดือนก่อน +2

    You're tutorials are fire!🔥

    • @KampaPlays
      @KampaPlays  10 หลายเดือนก่อน

      Thank you!!

  • @ebvs5ou
    @ebvs5ou ปีที่แล้ว +2

    Absolutely great set of tutorials ! Very well structured. Thank you very much.
    Really usefull small tipps now and then like "propfull"

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Great, thank you, glad it's helpful!

  • @owenschaff292
    @owenschaff292 ปีที่แล้ว +6

    This series is great and databindings seem amazing, cant wait to see all the ways they can be used!

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Thanks! They are pretty awesome. Soon we'll do some MVVM and put them to use really well.

  • @根本花里子
    @根本花里子 ปีที่แล้ว +1

    The topic seemed pretty complex, but I was able to understand it, thanks to your brilliant explanation!

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Really appreciate that!!!

  • @pierrestcergues
    @pierrestcergues ปีที่แล้ว +1

    ouah! I had to watch it couple of times, but now it's crystal clear.. thanks!

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Awesome! Glad it made sense!

  • @根本花里子
    @根本花里子 ปีที่แล้ว +1

    Ooooh, that is genius! Thank you very much for your amazing content!💖

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Thank you, glad to help!

  • @FionaldyAManik
    @FionaldyAManik ปีที่แล้ว +1

    BROOOO YOU'RE SO SMART, THIS IS SUPER HELPFUL!!!!!!!!!!!

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Glad it's helpful, thank you!!

  • @wookyumkim4669
    @wookyumkim4669 2 ปีที่แล้ว +5

    10:48 Oh, I can't wait for the video about DataGrid 😂😂

    • @KampaPlays
      @KampaPlays  2 ปีที่แล้ว +1

      Won't be long from now, will be doing ListView as well!

  • @DharmikGohil-bw2ug
    @DharmikGohil-bw2ug ปีที่แล้ว +1

    Really Great explanation Thanks 👏

  • @thomasaminer
    @thomasaminer 7 หลายเดือนก่อน

    Thank you. Now I understand how attributes work (I hope so)🙂

  • @yadmhedin972
    @yadmhedin972 9 หลายเดือนก่อน +1

    the best tutorial love you man

    • @KampaPlays
      @KampaPlays  8 หลายเดือนก่อน

      Thanks! Much love!

  • @UnityWorker
    @UnityWorker วันที่ผ่านมา

    Thank you very match!!

  • @bkoliver
    @bkoliver 6 หลายเดือนก่อน +1

    I have a stupid question, if I'm making four of these clearable text boxes, how do I add a variable that changes between the different boxes. the variable Boundtext works fine, but I am having trouble that each time I'm updating box 2-4, bound text is getting overwritten, I've tried referencing the clearabletextblock x:Name, but it's saying it can't convert that to a string. I know I'm missing something stupid.

  • @mjmo6919
    @mjmo6919 ปีที่แล้ว +1

    Very nice tutorial

  • @unkxxwn_name
    @unkxxwn_name ปีที่แล้ว +1

    I think I might got lost somewhere, its 3 AM, just yesterday I learned how to print Hello world on the console and now I am here

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Haha! That is awesome!! Everything making sense and sticking with you?

  • @nguyenmanh6751
    @nguyenmanh6751 ปีที่แล้ว +1

    thanks you very much

  • @furiouslobster7912
    @furiouslobster7912 ปีที่แล้ว +2

    Hey, you've mentioned several times "gooe"(?). Do you mean GUI or is it something else. English isn't my native language so it got me quite confused lol

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Yes, I'm saying "GUI", sorry for the confusion!

  • @jonathanmoore5619
    @jonathanmoore5619 8 หลายเดือนก่อน +1

    Great video. Can i just ask DataContext = this....
    Does that mean that the data associated with this wpf project.. is set and written within MainWindow? And could be set to another class, if you want? And what about if you have data in main window and an external or within project namespace class? How do you do that?

    • @KampaPlays
      @KampaPlays  8 หลายเดือนก่อน

      Yes, and yes! Generally when you do this you create a "ViewModel" and assign the data context to that, separating your UI from your logic (very similar to controller in MVC). Tutorial #23 goes over the basics of creating and using one.

    • @jonathanmoore5619
      @jonathanmoore5619 8 หลายเดือนก่อน

      @@KampaPlays thank you.

  • @azadalmohammad-rm7we
    @azadalmohammad-rm7we ปีที่แล้ว +1

    Keep up the Amazing Work!!

  • @priyankaabbineni4231
    @priyankaabbineni4231 ปีที่แล้ว +2

    Could you please do a video on wpf treeview controls in MVVM pattern and how to add data dynamically to treeview

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Will add this to my list! thanks!

  • @wms_ll
    @wms_ll 7 หลายเดือนก่อน

    Ты очень классно рассказываешь,🤟

  • @wookyumkim4669
    @wookyumkim4669 2 ปีที่แล้ว +2

    8:30 😆👏👏👏👏👏👏👏👏

  • @Onyx31415
    @Onyx31415 ปีที่แล้ว +4

    Hi, I really love the series so far.
    Why, do you create a public and private property for BoundText?

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว +5

      Thanks!!
      The public property requires a private backing variable to store the data. The property really only acts as a "getter" and "setter" of that private variable. Even if you create an auto-property (e.g. public string Text {get;set;}), the compiler will create this private backing variable for you. Here we need a full property, mainly so that we can define our PropertyChanged behavior in the property's set method. Does that answer your question?

    • @Onyx31415
      @Onyx31415 ปีที่แล้ว +3

      @@KampaPlays Ah, I'm a bit new to c# and didn't know it worked that way behind the scenes. Thanks a lot for your answer

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว +2

      No problem, great question!

  • @Silent-Scandals
    @Silent-Scandals 7 หลายเดือนก่อน

    getting error
    Error (active) CS0103 The name 'InitializeComponent' does not exist in the current context
    How to fix this this basically i have created custom component and all file showing this problem?

    • @potassiumzx
      @potassiumzx 3 หลายเดือนก่อน

      Hi,
      I got the same problem in VS Code. That is a false warning shown by C# Dev Kit extension. Currently, there is one temporary way to fix it. You have to put
      "

      True

      "
      (without the quotation marks) in your csproj file. Note that the path of MainWindows.g.cs could be different in your project so make sure to check it.
      This is for VS Code. I don't know if this will work on VS (Visual Studio) or not.

  • @vitalijgrabovan2061
    @vitalijgrabovan2061 ปีที่แล้ว

    Hello Krampa, I have one issue and it seems that I can’t find the answer on it, so I hope that you might help :)
    In my MainWindow I have a radio button with a XAML tag="*" in my MainWindow I can see that this tag has "*" as a parameter.
    The problem is that when I want to pass this Radio Button with that tag to my different class "MyClass" the tag name is empty="null" why it’s not passing?
    What do I need to do to pass the parameters from MainWindow to MyClass, is it done by Data Binding?
    Thank you.

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว +1

      It depends on the purpose of your other class. You might want to check out tutorial #23, It goes over ViewModels, which use databindings to get data from the UI to another class automatically -- that may be what you are needing.
      If a ViewModel-type interaction is not what you are after, I would recommend creating some state variable or object to represent your radio button(s) states and any other UI states, and do not pass the actual UI controls anywhere. For example, when your radio button state is changed (or other event):
      string radioTag = yourRadioControl.Tag;
      otherClass.Update(radioTag)

    • @vitalijgrabovan2061
      @vitalijgrabovan2061 ปีที่แล้ว +1

      @@KampaPlays Thanks I will try it :) I have solved this issue by adding a constrution in my class that i need to get a radio button Tag in and passed that value to it. Works quite good but I think its not the best solution.

    • @vitalijgrabovan2061
      @vitalijgrabovan2061 ปีที่แล้ว +1

      @@KampaPlays So I did watch your 23th video for several time to understand all of it and at the end I have solved my problem :) thanks your the best !!!

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Awesome!!! Thanks for letting me know!

  • @standman007
    @standman007 8 หลายเดือนก่อน +2

    100 likes for this tutorial. Thanks

    • @KampaPlays
      @KampaPlays  8 หลายเดือนก่อน

      Thank you!!

  • @AhmadAnwar31Aan
    @AhmadAnwar31Aan ปีที่แล้ว +1

    👍👍👏❤

  • @nubdevice4412
    @nubdevice4412 ปีที่แล้ว

    Umm what? Screw placeholder?
    Fine I accept defeat. Guess I'm going to just set it like I'm told not to.

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Sorry I don't understand, which part are you referring to?

    • @nubdevice4412
      @nubdevice4412 ปีที่แล้ว

      @@KampaPlays it's okay. I was a little disappointed this episode didn't apply well with the previous. Sucks being dumb.

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว +1

      Ha! I bet you are not dumb! This part of WPF can be really hard to get because so much of it happens like "black magic" behind the scenes. I tried breaking it up to best understand what is happening, but maybe it just wasn't how you needed to see it.
      So I think I understand now, but if not let me know. The previous video we set the control's property directly, which was a placeholder instead of implementing "OnPropertyChanged". I wanted the last videos focus to be on how to make a custom control and not pile on the bindings portion. So in this video, it shows how to implement the interface INotifyPropertyChanged so that you do not have to set the control's property directly, but instead call "OnPropertyChanged" to let it update via binding.
      I hope this helps!!

    • @anonstrider9136
      @anonstrider9136 4 หลายเดือนก่อน

      @@KampaPlays The previous episode had clearable texboxes and watermarks, however when i set up the onpropertychange the watermarks dont show anymore

  • @tsunamio7750
    @tsunamio7750 ปีที่แล้ว

    10:18 Have you ever heard of side-effect-programming?
    Please, end my suffering.
    I mean, WPF is easy... you just have to learn everything, and it does not apply to any other language or any other tool.
    This is pure horridness. Death shall feel good once I'm off this acursed playground of slow, bloated corporate shit.

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว

      Ha! Yes, there is a lot of behind-the-scenes 'black magic' that WPF (and so many other UI frameworks) does that I'm not a fan of. The suffering is extra real when you are forced to use strategies and patterns when they aren't necessary. They can be very useful in the right context, but if reasonable, save the separation of concerns worries and give me my visible, readable, and readily traceable code all day.
      I hope your suffering wanes, best of luck out there.

    • @tsunamio7750
      @tsunamio7750 ปีที่แล้ว

      @@KampaPlays Hey, I just made a whole Kanban UI. I'm delving into the MvvM. It's not so bad.
      I can't thank you enough. Once I get back to work, First salary, first tip for you

  • @SpeedSharp23
    @SpeedSharp23 ปีที่แล้ว +7

    Hi there. I've been learning how to code in c# for about 5 months now and decided I'd like to try adding GUI to my console applications. I found this playlist and I have to say...This is great. Simple to understand and easy to follow. However, there's one thing I just can't seem to understand.
    By using INotifyPropertyChanged and implementing PropertyChanged event, and then invoking it inside the setter of property, we can notify GUI about property change.
    What I don't understand is, if I'm not mistaken, when we invoke the event, event handler methods that are subscribed to the invoked event are supposed to start and they are supposed to do the logic part.
    But if I'm looking at the code right, you never created an event handler method that subscribes to the PropertyChanged event, so PropertyChanged event value should be null/nothing should happen, and yet PropertyChanged?.Invoke(...) worked.
    Am I missing something, or are event handler methods for PropertyChanged event already built-in, similarly to how events like Click seem to have built-in event invoking method?
    In other words, I'm trying to understand why PropertyChanged != null; at invoke time.
    Sorry for this long of a message. Hopefully, you understand what I'm asking, since english is not my first language.

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว +2

      Great question, and you are right. INotifyPropertyChanged and the PropertyChanged event does work a bit differently than a user-defined event, in that it is already "hooked up" for you for any compatible UI elements in your data context. All you need to do is implement the interface, and invoke the event telling it which control to notify, and the rest is done in the background.

    • @SpeedSharp23
      @SpeedSharp23 ปีที่แล้ว +1

      @@KampaPlays Nice. Shortcuts like these really make programming easier, but they also tend to confuse me when I'm trying to learn something 😅. In any case, thanks for your help 😊.

    • @KampaPlays
      @KampaPlays  ปีที่แล้ว +2

      @@SpeedSharp23 Totally understand that. While I'm used to most of the "black magic" behind-the-scenes WPFisms, I prefer to see the logic myself!
      Glad to help!

  • @deezburr
    @deezburr 6 หลายเดือนก่อน

    oh hell nah this is where i get lost 😭

    • @MonderMurshed
      @MonderMurshed 3 หลายเดือนก่อน

      How are you know ? did you moved on ?

  • @wms_ll
    @wms_ll 7 หลายเดือนก่อน +1

    Best WPF tutorial among I've found so far. Thank you so much.