Errors on build creating a UWP cppwinrt SolidColor

2019-08-23 07:24发布

问题:

When creating a solid brush (cppwinrt) for a textblock I get errors when building, using:

void MainPage::myStyle(Controls::TextBlock & block)
{   
    block.FontSize(72.0);
    block.Foreground(Media::SolidColorBrush(Windows::UI::Colors::Orange()));
    block.VerticalAlignment(VerticalAlignment::Center);     
}   

error: LNK2019 unresolved external symbol "public: __thiscall winrt::Windows::UI::Xaml::Media::SolidColorBrush::SolidColorBrush(struct winrt::Windows::UI::Color const &)"

The error goes when I take the solidbrush out and I've also tried other versions of the solidbrush with the same error.

回答1:

You need to

#include <winrt/Windows.UI.Xaml.Media.h>

to use types from namespace winrt::Windows::UI::Xaml::Media. This is documented under Get started with C++/WinRT:

Whenever you want to use a type from a Windows namespaces, include the corresponding C++/WinRT Windows namespace header file, as shown. The corresponding header is the one with the same name as the type's namespace. For example, to use the C++/WinRT projection for the Windows::Foundation::Collections::PropertySet runtime class, #include <winrt/Windows.Foundation.Collections.h>.



标签: uwp c++-winrt