Errors on build creating a UWP cppwinrt SolidColorBrush

▼魔方 西西 提交于 2019-12-13 06:31:34

问题


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



来源:https://stackoverflow.com/questions/53022168/errors-on-build-creating-a-uwp-cppwinrt-solidcolorbrush

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!