Skip to content

Commit 53ee6de

Browse files
authored
Clarify usage of ComponentConnectorT::InitializeComponent (#1161)
1 parent 4f0be70 commit 53ee6de

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

nuget/readme.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,19 @@ void MyComponent::InitializeComponent()
117117
A consequence of calling InitializeComponent outside construction is that Xaml runtime callbacks to IComponentConnector::Connect and IComponentConnector2::GetBindingConnector are now dispatched to the most derived implementations. Previously, these calls were dispatched directly to the class under construction, as the vtable had yet to be initialized. For objects with markup that derive from composable base classes with markup, this is a breaking change. Derived classes must now implement IComponentConnector::Connect and IComponentConnector2::GetBindingConnector by explicitly calling into the base class. The ComponentConnectorT template provides a correct implemenation for these interfaces:
118118

119119
```cpp
120-
struct DerivedPage : winrt::Windows::UI::Xaml::Markup::ComponentConnectorT<DerivedPageT<DerivedPage>>
120+
struct DerivedPage : winrt::Windows::UI::Xaml::Markup::ComponentConnectorT<DerivedPageT<DerivedPage>>
121+
```
122+
123+
If overriding DerivedPage::InitializeComponent, ComponentConnectorT::InitializeComponent should be called instead of DerivedPageT::InitializeComponent:
124+
125+
```cpp
126+
void DerivedPage::InitializeComponent()
127+
{
128+
// Call base InitializeComponent() to register with the Xaml runtime
129+
ComponentConnectorT::InitializeComponent();
130+
// Can now access Xaml properties from base or derived class
131+
MyBaseButton().Content(box_value(L"Click"));
132+
}
121133
```
122134

123135
## Troubleshooting

0 commit comments

Comments
 (0)