Adding ContentDialog item to UWP Blank App (C++/WinRT) fails to generate .g.h file?

Matthew Armshaw 41 Reputation points
2024-09-27T01:52:32.4733333+00:00

I am trying to add a ContentDialog item to UWP Blank App (C++/WinRT) project. With a fresh project of this type I choose Add New Item > XAML > ContentDialog. Once the item is added to the project it no long builds successfully - a error 'C1083: Cannot open include file: 'cd1.g.h': No such file or directory' is returned where cd1 is the name I gave to the item upon creation. I searched the project directory in File Explorer and it does not exist. I tried solutions offered by this AI - rebuild, try adding the same item by Add Existing Item. No luck. Seems like Visual Studio is not generating the file, rather than a programming or setup problem? Can someone point me in the right direction?

matt

Universal Windows Platform (UWP)
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,078 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,709 questions
0 comments No comments
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 17,401 Reputation points Microsoft Vendor
    2024-09-27T03:11:12.85+00:00

    Hi @Matthew Armshaw ,

    Welcome to Microsoft Q&A!

    I am trying to add a ContentDialog item to UWP Blank App (C++/WinRT) project. With a fresh project of this type I choose Add New Item > XAML > ContentDialog.

    The ContentDialog template you choose in Visual Studio generates C++/CX code, which is not C++/WinRT. It is recommended to add ContentDialog via code in C++/WinRT project.

    using namespace winrt::Windows::UI::Xaml::Controls;
    
     ContentDialog dialog;
     dialog.Title(box_value(L"Error"));
     dialog.Content(box_value(L"Please check and try again."));
     dialog.CloseButtonText(L"OK");
     dialog.ShowAsync();
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.