Replies: 1 comment 4 replies
-
This is one of the big reasons why I hate things like Copilot. It is unable to provide actual knowledge on things. But to dispel one illusion right away, in WinUI 3, there is no such thing as inheritance. Composition is the only option. Remember that WinUI 3 is a COM API under the surface. COM itself only supports interface inheritance, but the restricted form that WinUI uses, this is WinRT, then it doesn't even support interface inheritance. So, let's look under the covers a bit and actually see the definition of Microsoft.UI.Xaml.Controls.UserControl.
This is the MIDL2 definition of it, so it doesn't hide the ABI related stuff. Now, notice that the runtime class definition has a composable attribute? This tells any projection that another runtime class can compose. The thing here is that in projections, this looks like inheritance. What's more, UserControl also composes over Control. Yes, that syntax that looks like inheritance is a composable/composing relationship. Anyway, what you are doing should be pretty straight forward to do, but without knowing the errors then it is difficult to help. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In our application, we will have a whole suite of customized controls that will all share some common functionality. We would like to have something like the following hierarchy:
BaseControl : Microsoft.UI.Xaml.Controls.Control
SpecializedControl1 : BaseControl
SpecializedControl2 : BaseControl
....
We have been trying to set this up, but have only encountered various compiler errors. Copilot initially suggests this is easy to do, then changes its tune when asked about the compiler errors, saying the only proper way to accomplish this is either to use "composition", where there is no subclassing at all and the XAML for SpecializedControl1 includes a reference to BaseControl, or to use Templated Controls. "Composition" does not get us where we want, but is Copilot correct? Would Templated Controls be the only way to accomplish this?
It can be quite time consuming to set these scenarios up and try to slog through the compiler errors, so it would be really great to hear from someone with definite knowledge of what is possible and the correct approaches before spending lots more time seemingly in the weeds in Visual Studio.
Beta Was this translation helpful? Give feedback.
All reactions