I add Microsoft::UI::Xaml NuGet package to my C++/WinRT Blank App project will raised error.
Output message:
1>------ Rebuild All started: Project: TxtRecordGenerator, Configuration: Debug x64 ------ 1>64 bit MIDLRT Processing C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\App.idl 1>App.idl 1>64 bit MIDLRT Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt\winrtbase.idl 1>winrtbase.idl 1>64 bit MIDLRT Processing C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt\midlbase.idl 1>midlbase.idl 1>Processing WinMD 1>Processing input metadata file x64\Debug\Unmerged\App.winmd. 1>Processing input metadata file x64\Debug\Unmerged\MainPage.winmd. 1>Processing input metadata file x64\Debug\Unmerged\XamlMetaDataProvider.winmd. 1>Saved output metadata file TxtRecordGenerator.winmd. 1>Validating metadata file x64\Debug\Merged\TxtRecordGenerator.winmd. 1>pch.cpp 1>App.cpp 1>MainPage.cpp 1>module.g.cpp 1>XamlTypeInfo.Impl.g.cpp 1>XamlTypeInfo.g.cpp 1>C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\XamlTypeInfo.g.cpp(919,77): error C2039: 'XamlTypeInfo': is not a member of 'winrt::Microsoft::UI::Xaml' 1>C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\winrt\Microsoft.UI.Xaml.Controls.h(16562): message : see declaration of 'winrt::Microsoft::UI::Xaml' 1>C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\XamlTypeInfo.g.cpp(919,65): error C3083: 'XamlTypeInfo': the symbol to the left of a '::' must be a type 1>C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\XamlTypeInfo.g.cpp(919,79): error C2039: 'XamlControlsXamlMetaDataProvider': is not a member of 'winrt::Microsoft::UI::Xaml' 1>C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\winrt\Microsoft.UI.Xaml.Controls.h(16562): message : see declaration of 'winrt::Microsoft::UI::Xaml' 1>C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\XamlTypeInfo.g.cpp(919,111): error C3861: 'XamlControlsXamlMetaDataProvider': identifier not found 1>Done building project "TxtRecordGenerator.vcxproj" -- FAILED. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
This seems to be the error WinRT C++ code generator caused.
The C++/WinRT project code file as follows:
pch.h code:
#pragma once
#include <windows.h>
#include <unknwn.h>
#include <restrictederrorinfo.h>
#include <hstring.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.UI.Xaml.h>
#include <winrt/Windows.UI.Xaml.Controls.h>
#include <winrt/Windows.UI.Xaml.Controls.Primitives.h>
#include <winrt/Windows.UI.Xaml.Data.h>
#include <winrt/Windows.UI.Xaml.Interop.h>
#include <winrt/Windows.UI.Xaml.Markup.h>
#include <winrt/Windows.UI.Xaml.Navigation.h>
#include <winrt/Microsoft.UI.Xaml.Controls.h>
MainPage.idl:
namespace TxtRecordGenerator
{
[default_interface]
runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
{
MainPage();
}
}
MainPage.h:
#pragma once
#include "MainPage.g.h"
namespace winrt::TxtRecordGenerator::implementation
{
struct MainPage : MainPageT<MainPage>
{
MainPage();
};
}
namespace winrt::TxtRecordGenerator::factory_implementation
{
struct MainPage : MainPageT<MainPage, implementation::MainPage>
{
};
}
MainPage.cpp:
#include "pch.h"
#include "MainPage.h"
#include "MainPage.g.cpp"
using namespace winrt;
using namespace Windows::UI::Xaml;
namespace winrt::TxtRecordGenerator::implementation
{
MainPage::MainPage()
{
InitializeComponent();
}
}
MainPage.xaml:
<Page
x:Class="TxtRecordGenerator.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TxtRecordGenerator"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<CalendarDatePicker x:Name="BeginDatePicker"
PlaceholderText="Pick a date"
Header="Begin Date"
Foreground="{ThemeResource SystemAccentColorLight1}"
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
<CalendarDatePicker x:Name="EndDatePicker"
PlaceholderText="Pick a date"
Header="End Date"
Foreground="{ThemeResource SystemAccentColorLight1}"
Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
<controls:NumberBox x:Name="BeginNumberBox"
Header="Enter an integer:"
Value="1"
SpinButtonPlacementMode="Compact"
SmallChange="10"
LargeChange="100"
Grid.Row="1"
Grid.Column="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<controls:NumberBox x:Name="EndNumberBox"
Header="Enter an integer:"
Value="1"
SpinButtonPlacementMode="Compact"
SmallChange="10"
LargeChange="100"
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Grid>
</Page>
Development Environment:
IDE: Visual Studio 2019
UWP project target version: Windows 10, version 1903(10.0; Build 18362)
UWP project min version: Windows 10, version 1903(10.0; Build 18362)
This question confuses me. Can anyone help me?
First, you need to declare WinUI application resources in App.xaml:
<Application ......>
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
</Application.Resources>
</Application>
Then also add the following header file.
#include "winrt/Microsoft.UI.Xaml.XamlTypeInfo.h"
About more details, you can refer to this document: A simple C++/WinRT Windows UI Library example.