C#/WPF Building Custom Controls

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

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

  • @chillbro2275
    @chillbro2275 3 года назад +3

    hahaha Kevin man it was so much fun to listen to you live dev life. Especially the parts where you were perplexed. haha so funny to see another person go through that. Nice video man.

    • @Kitokeboo
      @Kitokeboo  3 года назад +1

      Thanks, I have a lot of fun programming and love to share that experience with others.

    • @chillbro2275
      @chillbro2275 3 года назад +1

      @@Kitokeboo it shows! I've thought about changing the look of a control that i think is ugly. But before i did that, i tried using the control regularly to bind data to it, and it wasn't quite right. So, well done to you.

  • @JO-qd2bv
    @JO-qd2bv 2 года назад +1

    This is a great video and Kudos to you for putting it out there. I think you could have saved a lot of time debugging the binding of your text value merely by looking at the Output Window while having Debug settings dump binding warning messages. Alternately a converter devoted to nothing but logging and returning the value it is given (effectively a do-nothing converter) is a useful way to debug bindings as it lets you insert a breakpoint and examine the value handed to the control in the debugger. Note that I'm not saying this so much for your benefit (I suspect you already know it) as for the people watching the video

    • @Kitokeboo
      @Kitokeboo  2 года назад

      This is a great tip and thanks for sharing. I have done that in the past but often forget about it.

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

    Hi, thanks for sharing all this ! I'm pretty new to WPF/XAML/UWP, I'm working on a UNO project and try to come together with learning XAML/WPF. But documentation is .... not clear and somtime dated. What's your advises as learning path ? I'm pretty comfortable with C# and OO, comming from a C++ background. Could you cover building custom/usercontrol with a content presenter ?

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

    11:15 Line 14 which has _new PropertyMetadata(default(int))_ gives me an error:
    _boxing allocation conversion from int to object requires boxing of the value type_
    I believe the PropertyMetadata constructor takes an object, and my IDE is complaining that it doesn't like passing an int for this object.

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

      This correct. The reason for this is largely historical. C# generics were a fairly new concept at the point WPF was release (only been out for about a year). The compiler is accurately flagging the fact that passing default value (0) into the PropertyMetadata constructor is causing the value to be boxed. Typically, you want to try to avoid boxing operators as they are computationally expensive (more details in the docs: learn.microsoft.com/dotnet/csharp/programming-guide/types/boxing-and-unboxing) Unfortunately in WPF there is not really a way to avoid boxing since the framework APIs force the default values into a reference type (object). In these cases, you just need to suppress the warning as there is no way to avoid the boxing altogether.
      Though not common practice, you can mitigate the number of boxing operations by performing a single boxing operation and caching the value. Something like this:
      private static readonly object Zero = 0;
      ...
      new PropertyMetadata(Zero)
      ...

  • @josbexerr5166
    @josbexerr5166 3 года назад +1

    excelente......gracias Mister Bost

  • @Moosa_Says
    @Moosa_Says 2 года назад

    Best by the best man :) Thanks a lot for this !

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

      I appreciate the kind words. Happy coding!

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

    you missed the "propd" snippet ;)

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

      Thanks. I do forget about those sometimes

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

    Hi Kevin, great video. I have a problem with:
    ContentWrapperGrid.RenderTransform = Scale = new ScaleTransform(1, 1);
    When I try to run the application I get an exceptionthat and I have not been able to solve:
    System.NullReferenceException: 'Object reference not set to an instance of an object.'
    CustomControlKevinBost.CustomControls.StarRating.ContentWrapperGrid.get returned NULL.
    How can I solve this? Thanks.

    • @Kitokeboo
      @Kitokeboo  2 года назад

      Hi Carlos
      Based on that error there are a few things to check
      1) The error indicates that after the ApplyTemplate method was called, the expected Grid was null. Check the ControlTemplate in the XAML to ensure there is a Grid with an x:Name="PART_Content"
      2) Ensure that the control template is getting loaded for the control. In my sample code this is using an implicit style to ensure the Template property of the control is getting the custom control template.
      3) Finally make sure that the resource dictionary that contains the ControlTemplate and style is being loaded. In my sample this is being done in the MainWindow.xaml where the RatingControlStyle.xaml is referenced as a merged dictionary.
      I have re-run the code and I am unfortunately not able to replicate the issue with the code in the repo. Are you running it from there, or somewhere else?

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

      @@Kitokeboo Hi Kevin, I've been off duty for several days. You were right, I was ignoring some tests that I did.
      with the , that was the error. Thanks for answering.

  • @_just_nothing__
    @_just_nothing__ 3 года назад

    Is it possible to create a custom control for playing video in WPF

    • @Kitokeboo
      @Kitokeboo  3 года назад

      It is, but you end up needing to implement nearly all of the video player type functionality. The FFME project that I showed there (github.com/unosquare/ffmediaelement) is a great example of one possible implementation of creating a custom control for video playback.

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

    Learned a lot by following this tutorial, thank you so much for sharing it!
    I just have one question that its: What exactly the lines like [TemplatePart(Name = ..., Type = typeof(...))] in the StartRating class are?
    I understand what they do since you explained it, which is basically retriving the controls defined in the StyleTemplate of the custom component by their nameof and their typeof, but what I'm trying to ask is what type of sentence those lines are? Are like other type of attributes, instances or what?
    I'm still pretty novice in C# and I don't quite recall something similar to that in other languages, so I'd like if you could clarify it.
    Wishing you a wonderful day:)!

    • @Kitokeboo
      @Kitokeboo  3 года назад +1

      Hi Decker, glad you found the stream helpful.
      To answer your questions. From a C# language perspective, yes those line are attributes. In C# attributes are a convenient way to attach additional metadata to C# constructs (in this case a class). Because this metadata is attached to the class at compile time, there are some limitations to the values you can place in those properties; specifically the values must be known at compile time (this typically means a constant).
      You can read more about them here: docs.microsoft.com/dotnet/csharp/language-reference/language-specification/attributes
      Hope that helps clarify it.

  • @ecedlnsskn
    @ecedlnsskn 3 года назад +1

    Why is it So hard gosh .... :(( Thank you for the video