C# WPF Tutorial #7 - Custom Textbox Control

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

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

  • @volkangundogdu1008
    @volkangundogdu1008 Год назад +18

    I guess the followers forget to press like button as the videos are very exiting that keep them focused very much on the content and then the next videos comes up. Another super feature is that you go directly into the point and give a lot of valuable information in a moment. Thanks a lot great content and efforts. ❤❤❤

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

      Thanks so much, that means a lot!

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

    Your professionalism and experience clearly come through in each of your videos. Glad to have the opportunity to learn from someone like you, sir. You are as fluid in your workflow as you are lucid in your explanations. This could not be any better. Thank you.

  • @jjk15
    @jjk15 Год назад +8

    Currently binge watching this series and I think it is amazing. Very easy to follow along and understand. Thank you!

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

      Awesome, thanks so much!

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

      I would have to agree. I am binge watching them too when I have time. Even if it’s just a few videos a day. I’m so used to winforms and tried making custom controls in there but thought I probably should just switch to WPF. And it seems much easier in WPF for stuff like that.

  • @PektraMom
    @PektraMom 11 месяцев назад +2

    I appreciate your time for these WPF tutorials. I'm going through my book and I barely understand and I have an exam in a few days. Your videos made me understand way better. Everything is well articulated and not in a fast manner. Also, I love the fact you are showing with your mouse cursor what is going on. Thank you for your precious time.

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

      Thanks so much. Very happy that it is helpful. Let me know if you have questions!

  • @dannyhunn6025
    @dannyhunn6025 2 года назад +3

    Love the way you are building it up step by step and using repetition from the last couple of videos

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

      Appreciate that!! I know it can be tedious, but I think it helps get a better understanding. Thanks for watching!

    • @dannyhunn6025
      @dannyhunn6025 2 года назад +1

      @@KampaPlays I got degrees in Computer Science and Electrical Engineering, most programming tutorials for beginners reminds me of the beginners courses in college designed to weed out people.

    • @KampaPlays
      @KampaPlays  2 года назад +4

      I agree, and that's one reason I decided to start making these videos. I understand time constraints, and the limitations of having 1 professor for hundreds of students, but that type of class is a great way to discourage many students from learning to program, and encourage others to copy/paste code from the internet with little understanding.

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

    Excellent tutorial series. You're a gifted teacher. Thank you for your efforts!

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

      Thanks so much, glad to help!

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

    Best WPF videos ever, keep going. looking forward to see more

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

      Thank you! Still making them!

  • @AnimeDecoder
    @AnimeDecoder Год назад +5

    I am new to programming and it was really easy following you. Thank you for your time. I would like to learn C# as well.

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

      Great and thank you! I have a beginner's C# series as well if you want to check it out. Feel free to ask any questions you have!

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

    Thanks, These tutorials are great, straight to the point and easy to follow. My only point is please increase the volume.

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

      Thanks! Sorry about that, I think I got it turned up sometime shortly after this video.

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

    Thank you Kampa, very well explained and the length of video are perfect.

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

    Thanks, man
    this tutorial is amazing. I enjoyed it a lot and learned a lot of things from it.

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

    A very concise explanation, thank you!

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

    F.Y.I, @11:48 The different video is
    Kampa plays, it would be better to add RUclips card at @11:48, for someone who wants the more explanation right away like me. :)

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

      Thanks for this, added a card to the video at 11:48!

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

    I love the Series. thank you

  • @robert-f4q8e
    @robert-f4q8e Год назад +1

    I got error: The name "ClearableTextBox" does not exist in the namespace "clr-namespace:WPFTutorial.View.UserControls".
    Microsoft Visual Studio Community 2022 (64-bit) - Current
    Version 17.6.3

    • @robert-f4q8e
      @robert-f4q8e Год назад +3

      Author didn't say *you must build your solution* before adding user control to the main form!

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

      Good catch - build early and often while using the XAML designer because until the referenced code is built it will give you false errors like these.

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

    So much effort for a such simple component

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

      It can definitely seem that way up front, and sometimes creating a custom control isn't necessary, but taking just a few minutes to create something that can be easily reused can save an incredible amount of future effort.

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

    If I am to use this user control textbox multiple times in a window or a page, can I do data binding again to differentiate each textbox and do different data validation on each of them?
    For example, first usercontrol for length and second for width, and length has min value of 1 but width has min value of 2

  • @MethodOverRide
    @MethodOverRide 2 года назад +2

    Another question I have is when creating this type of project, how important is it to start using a Class Library project? I would use the Class Library with folders to separate out the UI and code behind program code. Is that heading into more intermediate territory?

    • @KampaPlays
      @KampaPlays  2 года назад +1

      Definitely intermediate territory, and a very important topic. That being said, I would not start using class libraries until you have a real use case to do so. You would not separate your main UI XAML and the code behind itself, those should live together in the WPF project -- but you might find yourself wanting (or needing!) to move certain functionality into its own DLL that could be called from your WPF project.
      A couple of use cases for a class library:
      - WPF Common DLL: This could include your custom controls, styles, resources, and etc that you could include in other WPF projects.
      - Generic Logic DLL: Logic you might reuse anywhere (like encryption methods or other utility functions)
      - Solution Common DLL: Logic you need to separate out so that you can include it in multiple related projects. (For example, you may have a suite of tools that uses the same database, and you could use a class library to keep all that code in one place)
      Always remember to keep it simple and do what makes sense for your project. Doing a lot of this type of organization up front could add some value, but often once you get into implementation, plans change. It is very often more efficient to get a few working iterations under your belt, and then refactor/organize as needed.

    • @MethodOverRide
      @MethodOverRide 2 года назад +2

      @Kampa Plays thank you for the examples! It definitely helps as I try to balance implementing new topics at work.
      For example I was going to completely refactor this console app written 12 years ago to use OOP. However, after realizing how the program really works and that no one else would be able to help me maintain it, I opted to add new features to it that we needed. Took me maybe a few hours to do with testing instead of weeks for what would have been a full redo. I had to realize just because I knew a bit about OOP now that it didn't mean that OOP was the solution for everything.

    • @KampaPlays
      @KampaPlays  2 года назад +1

      @@MethodOverRide No problem, glad it helps!
      That's awesome. Many people, especially teachers, will preach the latest software engineering paradigms and design patterns as if they are the only correct way to solve any problem. Glad you are realizing this is not the case early! OOP and other methods, practices, and patterns, can be amazingly useful (and often are!), but there is no one-size-fits-all solution in the real world of software.

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

    very well explained thank you

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

    Its a neat start for a checkbox. But there are a few things about this, that i find... disturbing.
    1. The "Label"-Control exists for a reason.
    Given its purpose in HTML I'd assume, that one would need to use that for accessibility reasons instead of the text-block.
    2. A placeholder is not the same as a label. When all fields of the form contain a value, you still want to be able to see the headers for the fields.
    Otherwise it could become a little difficult when you have stuff like "firstname" & "lastname" filled out by a person from the other end of the world, and you have neither heard any of the names before - You would struggle to make the association.
    I personally like googles material design, where the placeholder becomes a header, once you either gain focus or have a value entered.
    That aside, I liked the video. Well explained stuff, just as a hint for the viewers:
    You might want to watch a UI/UX session, before diving into your code.

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

    Amazing tutorial. I have a question though:
    I want to go for a dark-themed form but I'm completely new to XAML. Anyway, I just set the Background property of the Grid in the main window and in the custom user control to #222222, and the Foreground property of the controls containing text to White. Now here's the problem:
    When I hover over the "x" (Clear) button of the custom user control, its background is changed to a very bright color and I want to change that. I want it to be darker. I tried asking ChatGPT how to change the button template but it didn't work out. It told me to locate the Template Property in the Property window and I found it but I could only create a new Template and so I gave up on that. I then tried to kind of overwrite the template's setting by adding an event MouseEnter (and MouseLeave) and changing the background color there but that also didn't work. Would you mind helping me out? If it is complicated, I will just leave it. It's not a big deal, I'm just curious. Thank you!

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

      Thanks! You are on the right track, but when it comes to button mouse over triggers you will need to override the default style. It can get a bit complicated, and I'll be doing some videos on it soon. That being said, here is a style block, that if you put into a or block inside your window or grid, it will target all buttons, override the style, and set a few properties like hover and disabled color, so you can dark theme it how you like. Hopefully that will help get you going!!
      codeshare.io/BAxXyL
      (Link expires in 24h)

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

      @@KampaPlays It worked. Thank you very much!

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

      Glad i could help!

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

    hello, question: in the time 10:32 you type string then you say that you press Tab Tab, then you do the same to change the name of the variable myVar this does not work for me, can you please tell me how to add this shortcut or funtionality?

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

      Hmm this should be standard in Visual Studio -- if you are making a property, you type "prop" then press tab tab.

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

    Very helpful video! I have a question though... Suppose I want to bind Text of in our . I've tried < (...)::ClearableTextBox (...) Text="{Binding ...}" (...) />, but that gives me an error.

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

      Thanks so much!
      That's a great question, but its a bit complicated (and that's why I didn't go over that bit yet, because it needs (and will get!) its own tutorial.
      So, there are 2 issues to deal with here:
      1. ClearableTextBox itself doesn't have a "Text" property.
      To solve this, you need to create what is called a dependency property. Inside ClearableTextBox.xaml.cs, add:
      public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(ClearableTextBox));
      public string Text
      {
      get => (string)GetValue(TextProperty);
      set => SetValue(TextProperty, value);
      }
      Now you should have access to "Text" property when creating a .
      2. You need the ability to bind ClearableTextBox's Text property to the Text Property of the TextBox that lives inside ClearableTextBox
      To do this - you need to use the RelativeSource property to allow access to this control from an ancestor. Add this property to the TextBox control inside ClearableTextBox.xaml:
      Text="{Binding Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type local:ClearableTextBox}}}"
      From there the TextBox's Text property should be tied to your ClearableTextBox, and you can bind the way you want:
      I know this is a lot -- I hope it helps you!!

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

      Thank you for your reply! It surely helped, but not enough. You see, I've created a class (which I call ViewData) and assigned my main window's DataContext to object of this class. Like this:
      ViewData viewData = new();
      public MainWindow()
      {
      InitializeComponent();
      DataContext = viewData;
      }
      And now, I'm trying to bind all my controls to View Data fields. In particular, there's a value of type double which I'm trying to get from clearableTextBox. And for some reason it doesn't work. Plain TextBox does the job, but I LOVE your clearableTextBox, my UI is so clean with it :)

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

      I see -- if TextBox works, then the above solution should work as well, even if bound to a double property in a ViewModel. Be sure that, even though you are using a ViewModel in this case, you still need to declare the dependency property inside ClearableTextBox.xaml.cs so it will link correctly.

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

      @@KampaPlays Thank you a lot! Next lesson solved all my problems. I wish you all the best!

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

      @@neijs_ Great!! Good job, and you too!

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

    Wow... great detailed tutorial... Thank you

  • @MethodOverRide
    @MethodOverRide 2 года назад +2

    Great video 👍
    I am starting to wonder at what point do we need to learn about dependency injection. It seems like it may be important when trying to update a project like this that has so many files. Do you plan on covering that in this tutorial?
    On a side note, I hope you have some time off for the holidays coming up! I'm off for two week. Hopefully I'll find some time in there to dabble on some of personal projects. 😁

    • @KampaPlays
      @KampaPlays  2 года назад +1

      Thank you!
      Dependency injection can be very useful, I plan on doing some tutorial videos on it, but probably not in the WPF series itself. I think I'll soon start up a general C# intermediate/advanced topics playlist where I can sprinkle in videos like that along the way.
      I do have a bit of time, I'll probably be busy working around the house! Enjoy your time off, good luck with your projects, and happy holidays!!

  • @ErcanMutlu-r4x
    @ErcanMutlu-r4x 5 месяцев назад

    When TxtBox set Text something then it thorw error "Object reference not set to an instance of an object"

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

    How would i get user input from these textboxes?

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

    It seems like ClearableTextBox class becomes a something like custom html tag in web dom or user defined React component,
    and a member variable (or a class property) of the ClearableTextBox class, which is the "private string placeholder" here, can be used in Xaml as like an html attribute, through "public string Placeholder".
    The reason why there are both "private string placeholder" and "public string Placeholder" at the same time is to follow usual OOP pattern.
    One cool thing here is that the "set" method of "public string Placeholder" is called through "=" operator, and it seems that it is c# wpf's built-in natural way.
    Am I on the right track Kampa?

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

      Spot on! Custom controls in WPF are very much like React components. Properties are one of my favorite things about C#! I have another video on them if you are interested.
      ruclips.net/video/OoYJy1s4zMY/видео.html

  • @santoshkshirsagar-ft2tq
    @santoshkshirsagar-ft2tq Год назад +1

    Great video

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

    Hi, I'm really enjoying these videos, but it's hard to follow and code at the same time. Is there a repository where I can find the solution with the code?

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

      Thank you!
      I don't keep repos for these intro tutorials, sorry. Once I get to some larger, more complex ones I will.

  • @subhashkethwas4786
    @subhashkethwas4786 21 день назад

    Why no recommendation pops up when i type something in my xaml code. Like if i write H it should show some popup optints like hight , and other words

  • @2000Renegade
    @2000Renegade Год назад +1

    4:50 General Kenobi

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

    I can't seem to import the textbox custom user control to the main file, just says its not in the clr namespace

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

      Sorry for the delay - you likely just need to build your solution for it to recognize that it is in the namespace. If that doesn't work, make sure to check your spelling matches.

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

      I was having the same issue. I Checked the spelling and it was all correct, i built the solution but i was still getting the error. To fix it I Cleaned the solution, rebuilt the solution, saved the project and restarted visual studio. dont know how it worked but it worked.

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

      @@KampaPlays bruh I was trying to fix this issue for 2 hours. thanks for the info. good video btw

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

    Hello, i think i need help for custom usercontrol texboxt to another page, I trying to make login page with custom ui textbox with databinding with username and password, so how to do it ya?

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

      I think what you would need here is your main window/control, that would have a handle to your login window (or view model), and on your login, have your custom control. Once the user enters text, the binding will send it to your login which can do what it needs to do and pass results back to your main window through its handle.

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

    Sir i am using visual studio 2012 there is no local xlmn to copy what do i do ?
    pls help thank you

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

      You might be able to add it in manually, but I do not know specifically for VS 2012. That version is no longer in support and I'm not sure that it even has the same version support we have here. I recommend you update your IDE before you proceed

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

    Excelente

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

    These are very good tutorials. I have been through them all i think now. Including Microsofts very out of date video,

  • @hungnguyen-bt7qj
    @hungnguyen-bt7qj 3 месяца назад

    niceee

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

    I understand the need to keep the video length kinda short but this usercontrol example is somewhat useless because there is no way (correct me if I'm wrong) the data entered or shown in the textbox can be used by an application. How can we go about setting/reading/getting notified of change, etc. I also understand that you cannot show everyting in one video but showing something that is basically unuseable in any kind of application only creates more questions. I think it's a bad editorial choice. I would have prefer having a two part video and have a comlete example. Nonetheless, thanks for your effort in bringing your knowledge to us.

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

      Apologies for the info shortcoming -- i was focused mainly on the concept of creating custom controls in WPF and the segue into data bindings, and not the actual implementation of the custom textbox. You could create properties and use data bindings to use this custom control, or you could bubble the events up. (For example, in the custom control, onclick could fire a local onclick that could be used in the appropriate place. I will definitely consider this in the future. All the best.

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

    Why X before Name?

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

      Honestly, it just autocompleted x:Name. I generally use Name if available, but it doesn't make any practical difference. x:Name is sometimes required to use if the element that you are using does not expose a "Name" property. All elements will have an x:Name because it is an artifact of the XAML element itself, and not the corresponding .NET class.

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

    Done : 2024/03/19

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

    This is not a custom control but a user control, the title is misleading.

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

      It's a custom user control yes, but user controls are very often just called "controls". Sorry for any confusion.

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

    cant you use auto-properties so you wouldnt have to set a public and private of the same field? why not do that?

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

      Admittedly I am out of date (been living in C++ land for a year), so .NET 7/8 may have introduced changes that make this possible, but -- here I do it that way because I'm setting up to use the INotifyPropertyChanged interface. (its not strictly needed here because I haven't gotten there yet, but I'm setting up the scaffolding). Hope this makes sense.