Beginning with C++/WinRT

Heiko 1,211 Reputation points
2020-10-21T12:32:36.737+00:00

Hi,

I have no experience with C++/WinRT. In VS 2017 15.9.28 I installed the VSIX extension, created a blank C++/WinRT UWP app, installed the CppWinRT Nuget package and tried to write some code. But I have no Intellisense and nothing of my own code is compilable.

In a C++/CX project the following code works well. How should this code look like in C++/WinRT style?

MainPage::MainPage()
{
    InitializeComponent();

    TextBlock ^textBlock = ref new TextBlock();

    textBlock->Text = L"Sampletext 1";
    textBlock->FontFamily = ref new Windows::UI::Xaml::Media::FontFamily(L"Trebuchet MS");
    textBlock->FontSize = 24;
    textBlock->FontWeight = FontWeights::Light;
    textBlock->FontStyle = Windows::UI::Text::FontStyle::Italic;
    textBlock->FontStretch = Windows::UI::Text::FontStretch::Normal;
    textBlock->CharacterSpacing = 0;
    textBlock->IsColorFontEnabled = false;
    textBlock->SetValue(Typography::StylisticAlternatesProperty, __abi_create_box(1));
    textBlock->SetValue(Typography::StandardSwashesProperty, __abi_create_box(0));
    textBlock->SetValue(Typography::ContextualSwashesProperty, __abi_create_box(0));
    textBlock->SetValue(Typography::AnnotationAlternatesProperty, __abi_create_box(0));
    textBlock->SetValue(Typography::StylisticSet2Property, false);
    textBlock->SetValue(Typography::StylisticSet3Property, true);
    textBlock->SetValue(Typography::EastAsianWidthsProperty, FontEastAsianWidths::Full);

    panelMain->Children->Append(textBlock);

    textBlock = ref new TextBlock();
    textBlock->Text = L"Sampletext 2";
    textBlock->FontFamily = ref new Windows::UI::Xaml::Media::FontFamily(L"Yu Gothic");
    textBlock->FontSize = 24;
    textBlock->FontWeight = FontWeights::Light;
    textBlock->FontStyle = Windows::UI::Text::FontStyle::Normal;
    textBlock->FontStretch = Windows::UI::Text::FontStretch::Normal;
    textBlock->CharacterSpacing = 0;
    textBlock->IsColorFontEnabled = false;
    textBlock->SetValue(Typography::StylisticAlternatesProperty, __abi_create_box(1));
    textBlock->SetValue(Typography::StandardSwashesProperty, __abi_create_box(0));
    textBlock->SetValue(Typography::ContextualSwashesProperty, __abi_create_box(0));
    textBlock->SetValue(Typography::AnnotationAlternatesProperty, __abi_create_box(5));
    textBlock->SetValue(Typography::StylisticSet2Property, false);
    textBlock->SetValue(Typography::StylisticSet3Property, true);
    textBlock->SetValue(Typography::EastAsianWidthsProperty, FontEastAsianWidths::Full);

    panelMain->Children->Append(textBlock);
}
Universal Windows Platform (UWP)
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,537 questions
{count} votes

Accepted answer
  1. Guido Franzke 2,196 Reputation points
    2020-10-23T10:17:15.577+00:00

    Hello,
    this is a known issue in Visual Studio 2017, according to this:
    intellisense-not-working-for-cwinrt-blank-app-temp.html
    cwinrt-intellisense-reports-too-many-errors-to-fun.html
    It is said that the IntelliSense error was fixed in Visual Studio 2019. So upgrade your developer studio.

    Regards, Guido


0 additional answers

Sort by: Most helpful