Closed takatsuka2022 closed 4 months ago
This seems to be related to #1319. Adding a .as
or .try_as
cast from spectrum
to xaml::FrameworkElement
before calling GetTemplateChild
should fix the break.
Also @sylveon for a second opinion on this topic.
GetTemplateChild has always been a protected method in WinRT metadata so this is an intentional result of this change. It was never meant to be public.
You can quickly workaround this issue by doing .as<IControlProtected>().GetTemplateChild()
, however the proper way to do what you're trying to do here is to extend ColorPicker and override OnApplyTemplate, or retemplate ColorPicker.
auto spectrum = MemoColorPicker().as<IControlProtected>().GetTemplateChild(L"ColorSpectrum").try_as<Controls::Primitives::ColorSpectrum>();
I wrote the above code, but the return value is NULL. Is this wrong?
This seems to work as expected for me:
Does your code work as expected with the previous versions of cppwinrt? Perhaps it runs before the template gets applied.
The problem has been resolved successfully. Thank you very much.
Version
2.0.240111.5
Summary
I think GetTemplateChild was a public function, but since 2.0.240111.5 it has been changed to protected, so I cannot access it from outside the class. Is there a workaround for this?
Reproducible example
Expected behavior
No response
Actual behavior
No response
Additional comments
No response