-
Notifications
You must be signed in to change notification settings - Fork 679
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
C++/WinRT - XAML control in a sub-folder doesn't work out of the box #7652
Comments
Subfolders are supposed to represent sub-namespaces. Change the sub-namespace of the XAML control to match the subfolder. |
Looks like it's still a problem even if you change the namespace. In that case, C++/WinRT prefixes the name of the header file with the subnamespace and then a dot (eg: Views.SettingsDialog.xaml.g.h). I would expect XAML to use the same name when the option to use subfolder for subnamespace files is not enabled. |
XAML uses the same directory structure in C#. It'll be probably easier to just update C++/WinRT to include the correct header. |
Please fix this issue soon. It gets quickly messy with having all XAML files in the root folder. |
If you move the generated files out of the subfolder and into the root it works as a workaround. Not ideal, but we already have to go into that folder and move/copy things around. |
This likely should be filed over at cpp/winrt. Seems its an issue with that compiler. |
Please look into this, really makes organising a codebase using WinUI in C++ harder. |
I've hit this issue when I wanted to basically have lots of applications sharing the same output directory. the .xaml files in the same directory meant that .xbf files would go into the wrong .pri files depending on racing conditions in the build process. So I wanted each C++ application to define a folder named like the project for its XAML files. The way I managed to have it build is to add "$(ProjectDir)\Generated Files\IndividualXAMLDirectoryNameForThisProject" to the |
I've hit the issue as well, and seem definitely related to how the XAML compiler outputs the generated files. Edit: OK, I've got a partial workaround: Assume your project folder structure looks like this: [MyProject] You can place your all your pages in the [MyProject][Views] folder and use the winrt::MyProject::Views to have a sub namespace for your views. However, you must prefix all your files with "Views.". So for example, the [MyProject][Views] folder will contain: This still looks a bit ugly, but at least you don't have all code files in the root of your project folder, and you can have sub namespaces. |
Describe the bug
When you keep XAML controls in a sub-folder, the project doesn't compile if you attempt to call, from the associated code behind file, any XAML-generated member function (eg: InitializeComponent or an element with x:Name). Specifically, this is caused as XAML Compiler saves the generated file(s) for the control inside a sub-folder under "Generated Files", but the header created by C++/WinRT assumes it's in the root of "Generated Files".
SettingsDialog.g.h from my project:
In this, the header doesn't include SettingsDialog.xaml.g.h as it's not there in the "Generated Files" root where SettingsDialog.g.h is present.
Steps to reproduce the bug
Expected behavior
You should be able to keep XAML control in a sub-folder.
Screenshots
No response
NuGet package version
No response
Windows app type
Device form factor
No response
Windows version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: