Thursday, June 12, 2008

[C#] Custom User Control Constructors [No Arguments]

So I was playing around with the new custom user controls I created for my ProgressBar etc... and I noticed that when I was trying to inject them into another XAML page that is in my project that the intellisense wasn't picking it up. It was like the control was not valid even though I was using the correct namespace, and could see my OTHER custom controls.

I started playing around and I noticed that I had ONE constructor for the control, and it took one parameter [I was setting a property or something with this parameter]. When I removed the argument from the function call [ie. public ProgressBar() {...}] - BAM - I could see the control via intellisense!

Again, this may be common knowledge, but it leads me to think that:
  • All custom user controls MUST contain a constructor with no arguments?
I'm guessing this is due to how inheritance is implemented, and had I REALLY thought about this earlier, I should have known this to be the case.

1 comment:

Anonymous said...

when you want to set property of your custom control through the constructor, what do you do?