Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProtectedCursor and GetTemplateChild API not functioning after updating C++/WinRT NuGet Package to the latest version #4980

Open
Ajith-GS opened this issue Dec 17, 2024 · 1 comment

Comments

@Ajith-GS
Copy link

Describe the bug

After updating the C++/WinRT NuGet package to the latest version 2.0.240405.15, certain properties and methods like GetTemplateChild and ProtectedCursor are no longer working as expected. These are worked fine in version 2.0.230706.1 of the C++/WinRT NuGet package, but they now generating build errors in the latest version and not even showing in VS IntelliSense.
Image

Steps to reproduce the bug

1. Create a WinUI 3 project in VS 2022.
2. Ensure the installed NuGet versions match the following. If not, update to the specified versions.


1.    Microsoft.Web.WebView2                             1.0.2651.64
2.    Microsoft.Windows.CppWinRT                         2.0.240405.15
3.    Microsoft.Windows.ImplementationLibrary            1.0.240803.1
4.    Microsoft.Windows.SDK.BuildTools                   10.0.26100.1742
5.    Microsoft.WindowsAppSDK                            1.6.241114003

3. Add the following code inside the button click handler.

       auto Obj1 = myButton().GetTemplateChild(L"ContentPresenter");
       auto Obj2 = myButton().ProtectedCursor();

4. Rebuild and run the project.

Expected behavior

The build process should be completed successfully without any errors.

Screenshots

Build Errors:
Image

NuGet package version

Windows App SDK 1.6.3: 1.6.241114003

Packaging type

Packaged (MSIX)

Windows version

Windows 10 version 22H2 (19045, 2022 Update)

IDE

Visual Studio 2022

Additional context

No response

@DarranRowe
Copy link

DarranRowe commented Dec 17, 2024

I believe this was by design.

ProtectedCursor is part of IUIElementProtected, which is defined as a protected interface for UIElement. It shouldn't have been part of the public interface generated by C++/WinRT in the first place. GetTemplateChild is similar, where it is part of the IControlProtected interface, which is define as a protected interface for Control. The only real supported way of accessing these is by deriving from a control to customise them.

There is a cheeky but unsuported way to keep doing what you wish to do though, that is querying for these protected interfaces. I believe as<IUIElementProtected>(); or as<IControlProtected>(); should still give access to these members.

--Edit--

microsoft/cppwinrt#1319 is what I was thinking of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants