C# WPF Tutorial #4 - Code Behind

Поделиться
HTML-код
  • Опубликовано: 11 окт 2024

Комментарии • 51

  • @sgt.shaggy5065
    @sgt.shaggy5065 Год назад +8

    Made a little "Don't push the button" game with this lol. Thank you for making this series.

    • @KampaPlays
      @KampaPlays  Год назад +1

      That is awesome! Those types of button mashing games were some of the first apps I wrote myself, long time ago! :)

  • @evanmashack8242
    @evanmashack8242 10 месяцев назад +4

    You are very talented at explaining things simply.

  • @eedorian967
    @eedorian967 9 месяцев назад +4

    You teach way better than online paid courses! So glad I found your channel cuz ill make this playlist my number 1 to go to learn wpf. Thank you for making these vids, may your channel grow bigger!

    • @KampaPlays
      @KampaPlays  8 месяцев назад +1

      Thank you, I really appreciate that. Let me know if you have questions!

  • @SharpTiger14
    @SharpTiger14 Год назад +6

    Hey, just came across your videos, and am loving this series so far! Thanks so much for making these!

    • @KampaPlays
      @KampaPlays  Год назад +1

      Awesome, very glad to hear!

  • @htoohtoosan7648
    @htoohtoosan7648 Месяц назад

    Thank you very much. I am just a starter of studying WPF and your videos helping me alot.
    Easy understanding!

  • @wookyumkim4669
    @wookyumkim4669 Год назад +3

    I'm soooooo happy to study with this series. Your video is so good 😆😆😆

    • @KampaPlays
      @KampaPlays  Год назад +1

      Great to hear, thank you for watching!!

  • @guanchenpeng5180
    @guanchenpeng5180 Год назад +2

    Very useful and concise introduction!

  • @zajac4817
    @zajac4817 2 месяца назад

    A little late to the party but I just love the approach. I'm loving this tutorial and I'm making the most of it!

  • @MethodOverRide
    @MethodOverRide Год назад +6

    Really enjoying this series. I did notice in this video that your mic volume was a little low.

    • @KampaPlays
      @KampaPlays  Год назад +2

      I'm glad!!! And uh oh, because I've recorded pieces and parts for like 5 more videos.. ☠ Thanks for letting me know, I will turn it up!

  • @MrReMiX-sf1qb
    @MrReMiX-sf1qb Год назад +3

    Лучший! Спасибо большое

  • @SansarNeupane
    @SansarNeupane 6 месяцев назад +1

    I am learning. Hats up to you brother, i love you

    • @KampaPlays
      @KampaPlays  5 месяцев назад

      Awesome, much love!

  • @ArifBillahOnGoogle
    @ArifBillahOnGoogle 9 месяцев назад +1

    Coming from web dev, thigns are quite uneasy for me (you know plain HTML, CSS -> XAML, XML stuff). But you make things very easy to understand. Thank you.

    • @KampaPlays
      @KampaPlays  9 месяцев назад

      Glad its helpful, yes its a very different feel from web markup, especially if you are used to heavy CSS.

  • @mariaisabelcondealtamirano8140
    @mariaisabelcondealtamirano8140 Год назад +1

    Great series of videos !! It helped me a lot... I'm only beggining... but the explanations are very accurate.

    • @KampaPlays
      @KampaPlays  Год назад

      Thanks so much, glad to help!

  • @vertorenogaming888
    @vertorenogaming888 10 месяцев назад +1

    Wow, I have knowledge in HTML it uses almost the same property. I would be learning this thanks

  • @ShemuelObadjah
    @ShemuelObadjah 3 месяца назад

    Excellent!

  • @angeldepaz6407
    @angeldepaz6407 Год назад +1

    Amazing tutorial thanks man 🤝

  • @acessogeral1537
    @acessogeral1537 10 дней назад

    Nice tutorial.

  • @grimyx86
    @grimyx86 11 месяцев назад +1

    Hey man 👋, why would you make the variavle "bool running = false;" in the class and not in the MainWindow() or in the event handler? Also why would u put "running = ! running;" outside of the loop in the event handler and not in the class?
    I am still new to this and I am so confused, do I just not understand scope logic? Will I find out in later videos? Why am I missing this logic here?
    Greatly appreciate this video series! 🔥

    • @KampaPlays
      @KampaPlays  11 месяцев назад

      Hey!
      Yes, that is scope you are referring to.
      Q: why would you make the variavle "bool running = false;" in the class and not in the MainWindow() or in the event handler?
      A: we need to be able to save the variable state of running even after the event handler has completed. if we put it in the event handler, it would be destroyed when the event handler completed executing (goes out of scope). by putting it in the class, we are able to set it, and it persists as long as the class exists, so any time the event handler runs, we can check it.
      Q: Also why would u put "running = ! running;" outside of the loop in the event handler and not in the class?
      A: running = !running is logic toggling the boolean - we can't put logic like this in the class itself, because it would have no method of execution. it belongs in the event handler, because we want to toggle that variable every time that event handler runs
      I don't have a specific video on scope - but I do have a beginner C# tutorial series that goes over a lot of the basic details of the language itself, that might be helpful to go over before diving deeper into WPF.
      Hope this helps!

    • @grimyx86
      @grimyx86 11 месяцев назад

      This helps a lot, I understand the logic and reasoning now. Thanks for taking the time to respond to my comment, have a good one! @@KampaPlays 🤘

  • @charleslueker2597
    @charleslueker2597 Год назад +4

    The commercials are twice as loud as the audio, but good info

    • @KampaPlays
      @KampaPlays  Год назад +2

      Yikes, thanks for letting me know, hate when they max out ad volume. Will try to up my level so it won't be so jarring.

  • @marypaul9627
    @marypaul9627 Год назад +2

    New sub here great content

  • @64imma
    @64imma 9 месяцев назад +1

    8:00 It seems you can easily rename these things by going into the xaml.cs file, and doing the renaming there, rather than doing it in the xaml file THEN going to the xaml.cs file.

    • @KampaPlays
      @KampaPlays  8 месяцев назад

      Great tip. I should have done that, sometimes I autopilot and forget to 'work smarter not harder' things :)

  • @NiggaInTech
    @NiggaInTech Год назад +3

    Great series can't wait to continue following, i come from strictly SWift/SWiftUI, so I don't know the idiosyncrasy of Microsoft/C#/Visual Studio and your video helping connect dots. Best Regards!

    • @KampaPlays
      @KampaPlays  Год назад +1

      Awesome to hear!! Thank you for watching and let me know if you have any questions!

  • @ThatAnnoyingGuyOnTheInternet
    @ThatAnnoyingGuyOnTheInternet 6 месяцев назад

    Question:
    I have
    Then I add the button in code behind:
    Area1.Children.Add(newButton); //this makes sense, adding a child to "Area1"
    Canvas.SetLeft(newButton, 500); // *why do I have to reference "Canvas" instead of "Area1"?*
    Area1.SetLeft(newButton, 500); //this would make sense but doesn't work

    • @KampaPlays
      @KampaPlays  5 месяцев назад +1

      It's because SetLeft is a static method of the Canvas class - so it does not need to be called from an object of that class, but is called from the class itself. Can be confusing at times, especially mixing the object itself in.

    • @ThatAnnoyingGuyOnTheInternet
      @ThatAnnoyingGuyOnTheInternet 5 месяцев назад

      ​@@KampaPlays Thanks for the answer, that actually makes sense (even though it brings up more questions):
      How does it differentiate when I have multiple canvases? I know it does (tested it), but how does it know which canvas I'm talking about? For example (assume I have 2 Canvases, Area1 and Area2):
      Area1.Children.Add(newButton);
      Area2.Children.Add(newButton2);
      Canvas.SetLeft(newButton, 500); // which canvas are we talking about?
      Canvas.SetLeft(newButton2, 50); // same question again
      And if it finds the correct canvas "under the hood" (like getting parent of the passed element and going from there), why not just use
      newButton.setLeft(500);
      which could find the parent as well but would be more intuitive. The way it works just seems convoluted to me so, I would like to know the logic behind it...

    • @KampaPlays
      @KampaPlays  5 месяцев назад

      @@ThatAnnoyingGuyOnTheInternet All good questions.
      - It knows which canvas because it can find the parent of the given button (as you mentioned "under the hood").
      - You wouldn't want to do newButton.SetLeft(500) because then button would require attributes and methods like this for every single container it may or may not belong to (cumbersome and confusing)
      - It *could in theory* do canvasObject.SetLeft(button, 500) and store information that way specific to the Canvas object, but instead:
      - WPF/XAML use things called attached properties and dependency properties - so this is most likely a static method on the Canvas class creating one of those properties, and attaching it to your button. It makes things very modular, very reusable, very flexible, and very hard to understand sometimes 🤣
      learn.microsoft.com/en-us/dotnet/desktop/wpf/properties/attached-properties-overview?view=netdesktop-8.0

  • @contasfinalcontasfinal
    @contasfinalcontasfinal 10 месяцев назад

    9:08 cant u use switch case?

    • @KampaPlays
      @KampaPlays  10 месяцев назад

      Sure, would work the same. In my opinion for a boolean check, if-else is clearer to read. I usually use switch when there are several states/options to check.

  • @mojitharanasingha9808
    @mojitharanasingha9808 6 месяцев назад +2

    Done : 2024/03/18

  • @thierryd519
    @thierryd519 Год назад +1

    The audio is so low that you need to be in a church to understand!

    • @KampaPlays
      @KampaPlays  Год назад +2

      🤣 sorry about that, i turned it up at some point.