Errors on build creating a UWP cppwinrt SolidColor

2019-08-23 07:01发布

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.

标签: uwp c++-winrt
1条回答
成全新的幸福
2楼-- · 2019-08-23 08:01

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>.

查看更多
登录 后发表回答