C# WPF Tutorial #20 - Reusable Style Resources

Поделиться
HTML-код
  • Опубликовано: 14 июн 2024
  • Use style resources to make your applications much cleaner and more maintainable! Learn how to use global styles that apply to all controls within a scope, as well as defining explicit StaticResource styles that can applied per control. Also learn how to use ResourceDictionary and MergedDictionaries inside of App.xaml to easily apply and maintain styles across your entire application.
    Happy Coding!
    Chapters:
    0:00 Setup
    0:15 Why Reusable Styles?
    0:42 Use Case for Styles
    1:31 Creating and Applying a Style
    3:22 Overriding a Style
    4:33 Use Case for Explicit Style
    5:00 Creating and Applying an Explicit Style
    6:24 Limiting Style Scope
    7:20 Application-wide Styles
  • НаукаНаука

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

  • @fatemeh2222
    @fatemeh2222 7 дней назад

    Thank you for all the tutorials! They are one of the best ones I've ever seen. Simple, Useful, Practical explanation.

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

    I just keep coming back to your tutorials because here I just learn more than with my lectors in university. Thanks for all your effort.

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

      Really appreciate that! If you have any questions let me know!

  • @lyleask8718
    @lyleask8718 10 месяцев назад +6

    This playlist is great!! This is the most useful content on WPF I've found. It is both accurate and practical. Thank for taking the time to make these tutorials.

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

      Thanks so much! I'm glad they are helpful!

  • @abcabc-wl3ky
    @abcabc-wl3ky Год назад +2

    I just 'liked' all of your WPF videos. They are to the point and exactly what I need, so thanks a lot for all the work that you put into them. Having been away from programming for 20+ years, I found it very intimidating with all the UI choices (Forms, WPF, UWP, WIN UI 3, MAUI etc.). Last time I did Windows programming was with the first version of Borland C++ Builder in the late 90s. So I got lost on many other tutorials and luckily found your WPF tutorial. You are a great communicator/teacher and obviously a great coder. Keep up the good work :)

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

      Thank you so much!!
      I used Borland C++ Builder 5 in my first job, good times! 🙂
      It can definitely be a mess trying to figure it all out, because they change it up so often. I'm glad this has been helpful!

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

    This is great! It is like html-css in web-development! 😃😃So concise contents! Glad that you are making this series😁😁

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

      For sure!! Thank you so much!

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

    These tutorials are GEM 😍Please keep them coming!

  • @bartsworkshop
    @bartsworkshop 4 месяца назад +1

    wow, you make everything so simple and easy to understand. Great video!

  • @nageshparitala
    @nageshparitala 7 месяцев назад +1

    Great material and awesome explanation, really enjoyed your thoroughness.

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

      Thanks so much, appreciate that!

  • @user-lq5fh2mp3r
    @user-lq5fh2mp3r 8 месяцев назад +1

    Exactly the instruction I was looking for!

  • @massimochiapelli3366
    @massimochiapelli3366 4 месяца назад +1

    Great, thanks a lot!!!

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

    Found this subscribed and will be following from now. Great content.

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

      Awesome, thank you!

  • @Elliot-7972
    @Elliot-7972 2 месяца назад +1

    thanks!

  • @bvc-vidadeprf9064
    @bvc-vidadeprf9064 Год назад +1

    Thanks for the tutorial ❤

  • @abdulmagedal-khulaifi6410
    @abdulmagedal-khulaifi6410 10 месяцев назад +1

    Thank you very much, very useful

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

    Here is the starting code for main window: (for the next 4 videos, I will try to add as well.):

  • @user-zc8fh1zk9x
    @user-zc8fh1zk9x Год назад +1

    Is very useful video! thank you for your shared! and i want to know will we learn about the complete Project for WPF & C#,like combine them?thank you!

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

      Thanks!
      Anytime we aren't writing XAML (such as in the code behind or a viewmodel), we are writing C#, so unless its pure GUI code, we are always combining them! 🙂

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

    Amazing tutorials, I watched all your videos in one evening. Everything is clear (like if english were my native tongue) and I finally feel I can use the different tools as it is designed to be used.
    I have a question for one of my projects I want to make with WPF (a video game launcher), I could just wait for your next videos but I don't know what you planned to show next. I would like to fetch a list of "objects" on a grid, where each object would be a custom user control (a kind of button to start a game, that also displays and contains infos about the related game).
    I thought the observable list could be a good solution since I don't know during design time how many games I will have to add to my grid (I get the list dynamically from a server request), but would it work with a list of custom user control and is a grid the best container to do what I want ?

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

      Thanks so much, I'm happy that they have helped!!
      You may be able to do what you want that way, but if you are fetching your collection from a server, I would suggest just loading your controls on server load and updating as needed. Also, there are a few better options than standard Grid for creating a dashboard look/feel.
      Here are my suggestions:
      1. Create your custom user control for your game buttons using basic UI elements like Grid
      2. Expose methods on your user control to be able to Load(gameData) this control with game-specific data from the server
      3. Create a dashboard user control using UniformGrid (you could also use a ListBox templated with a WrapPanel, but that's a bit more complicated)
      4. On server load, clear your dashboard and for each game you loaded, Load(gameData) one of your custom controls, and add it to your dashboard's item collection and let it handle the placement
      5. If you ever need intermediate updates without a full load, you could implement an Update() function on your custom controls and iterate over them all on demand or at some interval
      I hope this is helpful! I will be doing a tutorial on dashboard/custom control collections at some point in the future, but hopefully this will get you going!!

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

      @@KampaPlays Thx for your quick answer. That's close to what I had in mind, you gave me the missing pieces. I'll try to apply that when I have time. Thanks a lot !

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

      Great!! Best of luck!

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

      @@KampaPlays Hi Kampa! Thx again for the tips you gave me the other day. I gave a try on ListBox templated with a WrapPanel. This is awesome, that's exactly what I needed !
      But.. I have problem. To make it simple to explain, let's say my user control only has a string as data and a Button which is binded to my string in its Content property. In my window class, if I instantiate my user controls multiple times and fill an observable list with them, everything works fine.
      But if I place a break point in the button click function, I notice that my string data is null in the instance of user control where my break point triggers. It makes me think the UI retrieves the data from the correct ContextData to display my string in the button, but the button calls the button click function on an "data-empty" ContextData (my guess is that ListBox re-instanciates on the fly new user controls that I can't fill with data).
      Do you have any idea on how I could fix this issue ? I know I ask you a lot, if you don't have time, that's not a problem. Also I can provide you some code or a sample projet of my situation, to make it easier for you.

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

      Hey! I'm glad it was what you needed.
      I'm not sure exactly what that issue is without looking at it myself, i have a few ideas but they are just guesses at this point. Work is pretty demanding right now but if you will drop me a link to your code I will take a look when I can.

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

    Could Dictionaries still be used without merging them in one App.xaml file? Maybe I am just comparing this logic to how css works. But it seems more convenient to just import the style files(dictionaries) that I need instead of merging them all in one file and picking the styles I want by name.
    Why did we even separate them in separate files, if we were going to merge them and make them accessible globally?

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

    Thanks for the tutorial
    My event setters inside the style tags doesn't work after moving them to app.xaml
    do you know how any work around to solve this problem

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

      Sorry for the delay -- I'm not sure offhand but I would first check that your syntax is all correct after the move, and that you aren't missing any includes/dependencies. Also make sure you rebuild your solution. Hope you got it working.

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

    Are you planning to tell about mvvm in this tutorial?

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

      Yes, I'm starting MVVM in 2 videos!

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

    I have a question about what is the difference between Name and x:Name, when to use each one??

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

      Name is a generally available property on most UI element/content classes in the WPF framework, while x:Name is a field in the lower-level code created when the XAML is compiled. If they both exist either can be used, and work practically the same way. My preference is to use Name, except in the rare scenario where its not available, I'll use x:Name. Sometimes I will accidentally autocomplete x:Name, and just leave it! 🙂

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

    waiting for mvvm tutorials😥

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

      Will be a couple of weeks, have one more to go before i start MVVM. 👍