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 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.
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
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 ?
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.
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) ...
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.
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?
@@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.
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.
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:)!
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.
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.
Thanks, I have a lot of fun programming and love to share that experience with others.
@@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.
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
This is a great tip and thanks for sharing. I have done that in the past but often forget about it.
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 ?
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.
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)
...
excelente......gracias Mister Bost
Best by the best man :) Thanks a lot for this !
I appreciate the kind words. Happy coding!
you missed the "propd" snippet ;)
Thanks. I do forget about those sometimes
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.
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?
@@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.
Is it possible to create a custom control for playing video in WPF
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.
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:)!
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.
Why is it So hard gosh .... :(( Thank you for the video