Skip to content

InitializeComponent is not called for base classes. #1140

@sylveon

Description

@sylveon

With #1130, InitializeComponent is now called internally as part of winrt::make instead of within the constructor. This means that the following scenario, by default, does not work anymore:

  • Class A is a base class using XAML.
  • Class B derives from class A in metadata, and uses XAML too.
  • Both are within the same project, so implementation::B directly derives from implementation::A, instead of using WinRT composition.

C++/WinRT will call class B's InitializeComponent function, but the XAML compiler did not generate code in class B's InitializeComponent function to call class A's InitializeComponent function. As a result, nothing from class A is loaded: none of the XAML is visible, no event handlers are attached, x:Bind bindings are not set up, trying to access a x:Name'd control gives nullptr, ets.

To fix this, a user has to explicitly go and add the following in implementation::B:

void B::InitializeComponent()
{
    A::InitializeComponent();
    BT::InitializeComponent();
}

These kinds of things should be transparent to the user.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions