Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C2039和x9';XamlTypeInfo';:不是';winrt::Microsoft::UI::Xaml';在XamlTypeInfo.g.cpp中_C++_Uwp_Windows 10 Universal_C++ Winrt - Fatal编程技术网

C++ C2039和x9';XamlTypeInfo';:不是';winrt::Microsoft::UI::Xaml';在XamlTypeInfo.g.cpp中

C++ C2039和x9';XamlTypeInfo';:不是';winrt::Microsoft::UI::Xaml';在XamlTypeInfo.g.cpp中,c++,uwp,windows-10-universal,c++-winrt,C++,Uwp,Windows 10 Universal,C++ Winrt,我将NuGet包添加到我的C++/WinRT Blank应用程序项目将引发错误 输出消息: 1> ----已开始全部重建:项目:TxtRecordGenerator, 配置:调试x64-----1>64位MIDLRT处理 C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\App.idl 1> App.idl 1>64位MIDLRT处理C:\Program Files(x86)\Windows 工具包\

我将NuGet包添加到我的C++/WinRT Blank应用程序项目将引发错误

输出消息:

1> ----已开始全部重建:项目:TxtRecordGenerator, 配置:调试x64-----1>64位MIDLRT处理 C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\App.idl 1> App.idl 1>64位MIDLRT处理C:\Program Files(x86)\Windows 工具包\10\包括\10.0.18362.0\winrt\winrtbase.idl 1>winrtbase.idl 1>64 bit MIDLRT处理C:\Program Files(x86)\Windows 工具包\10\Include\10.0.18362.0\winrt\midlbase.idl 1>midlbase.idl 1> 处理WinMD 1> 正在处理输入元数据文件x64\Debug\Unmerged\App.winmd。 1> 正在处理输入元数据文件x64\Debug\Unmerged\MainPage.winmd。 1> 处理输入元数据文件 x64\Debug\Unmerged\XamlMetaDataProvider.winmd。1> 保存的输出元数据 文件TxtRecordGenerator.winmd。1> 验证元数据文件 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):错误C2039:“XamlTypeInfo”:不是 “winrt::Microsoft::UI::Xaml”的成员 1> C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\winrt\Microsoft.UI.Xaml.Controls.h(16562):消息:请参阅 “winrt::Microsoft::UI::Xaml”的声明 1> C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\XamlTypeInfo.g.cpp(919,65):错误C3083:'XamlTypeInfo':错误 “::”左侧的符号必须是类型 1> C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\XamlTypeInfo.g.cpp(919,79):错误C2039: “XamlControlsXamlMetaDataProvider”:不是的成员 'winrt::Microsoft::UI::Xaml' 1> C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\winrt\Microsoft.UI.Xaml.Controls.h(16562):消息:请参阅 “winrt::Microsoft::UI::Xaml”的声明 1> C:\Users\a124p\Documents\GitHub\VisualizationRecorder\TxtRecordGenerator\Generated Files\XamlTypeInfo.g.cpp(919111):错误C3861: “XAMLControlsXALMMetadataProvider”:未找到标识符1>完成 生成项目“TxtRecordGenerator.vcxproj”--失败。 =========全部重建:0成功,1失败,0跳过==========

这似乎是WrRT+C++代码生成器引起的错误。

C++/WinRT项目代码文件如下所示:

pch.h代码:

#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>
主页.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.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>

发展环境:

  • IDE:VisualStudio2019

    UWP项目目标版本:Windows 10,版本1903(10.0;内部版本 18362)

    UWP项目最低版本:Windows 10,版本1903(10.0;版本18362)


这个问题使我困惑。有人能帮我吗?

首先,您需要在App.xaml中声明WinUI应用程序资源:

<Application ......>
    <Application.Resources>
        <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
    </Application.Resources>
</Application>
有关更多详细信息,请参阅以下文档:

<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>
<Application ......>
    <Application.Resources>
        <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
    </Application.Resources>
</Application>
#include "winrt/Microsoft.UI.Xaml.XamlTypeInfo.h"