I have to modify an existing Control using the Loaded event from a static member function that has to:
Not storing the revoker into some class member because the code is inside a static function. Also, I don't want to store it somewhere else globally.
The
Loadedcallback should only be called once, so it needs to revoke itself.
Currently this is my solution
auto loadedRevoker = new winrt::Microsoft::UI::Xaml::Controls::CommandBar::Loaded_revoker;
*loadedRevoker = commandBar.Loaded(winrt::auto_revoke, [loadedRevoker](auto&& self, auto&&) {
//revoke event
loadedRevoker->revoke();
delete loadedRevoker;
//do something
});
It works, but I want to change it into using smart pointers and couldn't figure out a correct way.