{"id":4462,"date":"2022-04-08T21:31:36","date_gmt":"2022-04-08T19:31:36","guid":{"rendered":"https:\/\/mariusbancila.ro\/blog\/?p=4462"},"modified":"2022-04-08T21:31:39","modified_gmt":"2022-04-08T19:31:39","slug":"unwrapping-winui3-for-cpp","status":"publish","type":"post","link":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/","title":{"rendered":"Unwrapping WinUI3 for C++"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Windows UI Library 3, known shortly as WinUI 3, is a native UI framework that ships with the Windows App SDK. This is an SDK complementary to the Windows SDK, WPF, WinForms, and Win32. It provides a new unified set of APIs and tools that can be used to develop desktop apps on Windows 11 (as well as downwards to Windows 10, version 1809). I decided to have a look at what this framework provides and this post is written as I am trying it. To evaluate it, I&#8217;ll try to build a small application that does conversion between Celsius and Fahrenheit degrees as you type in a field.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Disclaimer<\/strong>: I have not build any app using the Universal Windows Platform or the WinRT technologies. Therefore, I expect to stumble upon issues that are simple or obvious for those familiar with these technologies. On the other hand, I do have experience building WPF applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting Started<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As briefly mentioned in the introduction, WinUI 3 is a new native framework that is part of the Windows App SDK. It sits on top of Win32 and Universal Windows Platform, providing a way to build applications that can run on a variety of platforms, such as PCs or mobile devices. Here is a picture from <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/apps\/winui\/winui3\/\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"Microsoft Docs\">Microsoft Docs<\/a> showing the relationship between these technologies:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/platforms-winui3.png\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"271\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/platforms-winui3-700x271.png\" alt=\"\" class=\"wp-image-4463\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/platforms-winui3-700x271.png 700w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/platforms-winui3-300x116.png 300w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/platforms-winui3-768x297.png 768w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/platforms-winui3-1536x594.png 1536w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/platforms-winui3.png 1578w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><figcaption>Source: https:\/\/docs.microsoft.com\/en-us\/windows\/apps\/winui\/winui3\/<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some resources to check to learn more about it:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/apps\/winui\/winui3\/create-your-first-winui3-app\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"Create your first WinUI 3 project\">Create your first WinUI 3 project<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/apps\/windows-app-sdk\/downloads\" title=\"Downloads for the Windows App SDK\" target=\"_blank\" rel=\"noreferrer noopener\">Downloads for the Windows App SDK<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/\" title=\"Microsoft Windows UI Library namespaces\" target=\"_blank\" rel=\"noreferrer noopener\">Microsoft Windows UI Library namespaces<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.xaml.controls?view=winui-3.0\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"WinUI3 Controls\">WinUI3 Controls<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To get started with WinUI 3 for C++, you need:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Visual Studio 2022<\/li><li>Windows App SDK<\/li><li>Visual Studio 2022 Extensions for C++<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The last two you can get from the second link above.<\/p>\n\n\n\n<div class=\"wp-block-uagb-inline-notice uagb-inline_notice__outer-wrap uagb-inline_notice__align-left uagb-block-4a14481b\"><h4 class=\"uagb-notice-title\">Impression: \u2b50\u2b50\u2b50\u2b50\u2b50<\/h4><div class=\"uagb-notice-text\"><p>Installing the pre-requisites is straight forward and I did not encounter any problem.<\/p><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Creating a first project<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After installing the pre-requisites, you can create new projects. You need to select <strong>C++<\/strong> for the language and the <strong>WinUI<\/strong> for the project type. From the available list then select <strong>Blank App, Packaged (WinUI 3 in Desktop)<\/strong>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/newproject.png\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"449\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/newproject-700x449.png\" alt=\"\" class=\"wp-image-4464\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/newproject-700x449.png 700w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/newproject-300x192.png 300w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/newproject-768x493.png 768w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/newproject.png 1171w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The following template project is created:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/solution.png\"><img loading=\"lazy\" decoding=\"async\" width=\"328\" height=\"562\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/solution.png\" alt=\"\" class=\"wp-image-4465\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/solution.png 328w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/solution-175x300.png 175w\" sizes=\"auto, (max-width: 328px) 100vw, 328px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The solution contains several files, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>App.xaml<\/code>, together with <code>App.idl<\/code>, <code>App.xaml.h<\/code>, and <code>App.xaml.cpp<\/code>. The <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.xaml.application?view=winui-3.0\" title=\"App\" target=\"_blank\" rel=\"noreferrer noopener\">App<\/a> class represents the current application and its services, such as entry point, lifetime management, unhandled exception detection.<\/li><li><code>MainWindow.xaml<\/code>, together with <code>MainWindow.idl<\/code>, <code>MainWindow.xaml.cpp<\/code>, <code>MainWindow.xaml.h<\/code>. The <code>MainWindow<\/code> class is derived from the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.xaml.window?view=winui-3.0\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"Window\">Window<\/a> class and represents a window of the application.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is how the <code>App<\/code> class looks:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ --- App.xaml.h ---\nnamespace winrt::WinUIApp::implementation\n{\n    struct App : AppT&lt;App>\n    {\n        App();\n\n        void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&amp;);\n\n    private:\n        winrt::Microsoft::UI::Xaml::Window window{ nullptr };\n    };\n}\n\n\n\/\/ --- App.xaml.cpp ---\n#include \"App.xaml.h\"\n#include \"MainWindow.xaml.h\"\n\nusing namespace winrt;\nusing namespace Windows::Foundation;\nusing namespace Microsoft::UI::Xaml;\nusing namespace Microsoft::UI::Xaml::Controls;\nusing namespace Microsoft::UI::Xaml::Navigation;\nusing namespace WinUIApp;\nusing namespace WinUIApp::implementation;\n\n\/\/ To learn more about WinUI, the WinUI project structure,\n\/\/ and more about our project templates, see: http:\/\/aka.ms\/winui-project-info.\n\n\/\/\/ &lt;summary>\n\/\/\/ Initializes the singleton application object.  This is the first line of authored code\n\/\/\/ executed, and as such is the logical equivalent of main() or WinMain().\n\/\/\/ &lt;\/summary>\nApp::App()\n{\n    InitializeComponent();\n\n#if defined _DEBUG &amp;&amp; !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION\n    UnhandledException([this](IInspectable const&amp;, UnhandledExceptionEventArgs const&amp; e)\n    {\n        if (IsDebuggerPresent())\n        {\n            auto errorMessage = e.Message();\n            __debugbreak();\n        }\n    });\n#endif\n}\n\n\/\/\/ &lt;summary>\n\/\/\/ Invoked when the application is launched normally by the end user.  Other entry points\n\/\/\/ will be used such as when the application is launched to open a specific file.\n\/\/\/ &lt;\/summary>\n\/\/\/ &lt;param name=\"e\">Details about the launch request and process.&lt;\/param>\nvoid App::OnLaunched(LaunchActivatedEventArgs const&amp;)\n{\n    window = make&lt;MainWindow>();\n    window.Activate();\n}\n\n\/\/ --- App.xaml.idl ---<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On the other hand, the <code>MainWindow<\/code> class looks as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ --- MainWindow.xaml.h ---\n#pragma once\n\n#include \"MainWindow.g.h\"\n\nnamespace winrt::WinUIApp::implementation\n{\n    struct MainWindow : MainWindowT&lt;MainWindow>\n    {\n        MainWindow();\n\n        int32_t MyProperty();\n        void MyProperty(int32_t value);\n\n        void myButton_Click(Windows::Foundation::IInspectable const&amp; sender, Microsoft::UI::Xaml::RoutedEventArgs const&amp; args);\n    };\n}\n\nnamespace winrt::WinUIApp::factory_implementation\n{\n    struct MainWindow : MainWindowT&lt;MainWindow, implementation::MainWindow>\n    {\n    };\n}\n\n\/\/ --- MainWindow.xaml.cpp ---\n#include \"pch.h\"\n#include \"MainWindow.xaml.h\"\n#if __has_include(\"MainWindow.g.cpp\")\n#include \"MainWindow.g.cpp\"\n#endif\n\nusing namespace winrt;\nusing namespace Microsoft::UI::Xaml;\n\n\/\/ To learn more about WinUI, the WinUI project structure,\n\/\/ and more about our project templates, see: http:\/\/aka.ms\/winui-project-info.\n\nnamespace winrt::WinUIApp::implementation\n{\n    MainWindow::MainWindow()\n    {\n        InitializeComponent();\n    }\n\n    int32_t MainWindow::MyProperty()\n    {\n        throw hresult_not_implemented();\n    }\n\n    void MainWindow::MyProperty(int32_t \/* value *\/)\n    {\n        throw hresult_not_implemented();\n    }\n\n    void MainWindow::myButton_Click(IInspectable const&amp;, RoutedEventArgs const&amp;)\n    {\n        myButton().Content(box_value(L\"Clicked\"));\n    }\n}\n\n\/\/ --- MainWindow.xaml.idl ---\nnamespace WinUIApp\n{\n    [default_interface]\n    runtimeclass MainWindow : Microsoft.UI.Xaml.Window\n    {\n        MainWindow();\n        Int32 MyProperty;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">What I can see from here is that:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>There are two classes called <code>MainWindow<\/code>, both derived from the class template <code>MainWindowT<\/code>, except with different template arguments. However, they are part of two different namespaces: one is called <code>implementation<\/code> and the other is called <code>factory_implementation<\/code>. At a first look, I find this confusing, but will probably understand it better lately.<\/li><li>The code to set the text content of the button on the window is cumbersome. It looks like this: <code>myButton().Content(box_value(L\"Clicked\"))<\/code>. <code>myButton<\/code> is an object that&#8217;s defined in the <code>MainWindow.xaml<\/code> file but it&#8217;s accessed through a function. And there&#8217;s this <code>box_value<\/code> wrapper for the string. <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">There is also the <code>MainWindow.xaml<\/code> file that looks as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;Window\n    x:Class=\"WinUIAppDemo.MainWindow\"\n    xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n    xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n    xmlns:local=\"using:WinUIAppDemo\"\n    xmlns:d=\"http:\/\/schemas.microsoft.com\/expression\/blend\/2008\"\n    xmlns:mc=\"http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006\"\n    mc:Ignorable=\"d\">\n\n    &lt;StackPanel Orientation=\"Horizontal\" HorizontalAlignment=\"Center\" VerticalAlignment=\"Center\">\n        &lt;Button x:Name=\"myButton\" Click=\"myButton_Click\">Click Me&lt;\/Button>\n    &lt;\/StackPanel>\n&lt;\/Window><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you double click it, it opens it with the <strong>Source Editor<\/strong>. If you try to run the <strong>Open with&#8230;<\/strong> command and select <strong>XAML Designer<\/strong> nothing happens. There is an <strong>Design in Blend<\/strong> option, but it&#8217;s the same problem:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/blend.png\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"219\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/blend-700x219.png\" alt=\"\" class=\"wp-image-4470\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/blend-700x219.png 700w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/blend-300x94.png 300w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/blend-768x240.png 768w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/blend.png 1054w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><figcaption>The XAML file opened in Blend.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I can only conclude that designing WinUI 3 visual elements is not possible with the designer so you need to do everything by hand and run the application to see how the UI looks. That&#8217;s a huge minus, in my book, and defeats most of the purpose of having a UI framework. But maybe it&#8217;s my fault and I missed installing something. After all, I&#8217;m just trying things.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you build the project, a folder called <strong>Generated Files<\/strong> is created, containing, as the name suggests, files generated from existing source code. These include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>App.xaml.g.hpp<\/code> and <code>App.xaml.g.cpp<\/code> for the <code>App<\/code> class.<\/li><li><code>MainWindow.xaml.g.hpp<\/code> and <code>MainWindow.xaml.g.cpp<\/code> for the <code>MainWindow<\/code> class.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The generated header for the <code>MainWindow<\/code> class looks as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#pragma once\n\nnamespace winrt::WinUIAppDemo::implementation\n{\n    using IInspectable = ::winrt::Windows::Foundation::IInspectable;\n\n    template &lt;typename D, typename ... I>\n    struct MainWindowT : public ::winrt::WinUIAppDemo::implementation::MainWindow_base&lt;D,\n        ::winrt::Microsoft::UI::Xaml::Markup::IComponentConnector,\n        I...>\n    {\n        using base_type = typename MainWindowT::base_type;\n        using base_type::base_type;\n        using class_type = typename MainWindowT::class_type;\n\n        void InitializeComponent();\n        void Connect(int32_t connectionId, IInspectable const&amp; target);\n        ::winrt::Microsoft::UI::Xaml::Markup::IComponentConnector GetBindingConnector(int32_t connectionId, IInspectable const&amp; target);\n        void UnloadObject(::winrt::Microsoft::UI::Xaml::DependencyObject const&amp; dependencyObject);\n        void DisconnectUnloadedObject(int32_t connectionId);\n\n        ::winrt::Microsoft::UI::Xaml::Controls::Button myButton()\n        {\n            return _myButton;\n        }\n        void myButton(::winrt::Microsoft::UI::Xaml::Controls::Button value)\n        {\n            _myButton = value;\n        }\n        \n    protected:\n        bool _contentLoaded{false};\n\n    private:\n        struct MainWindow_obj1_Bindings;\n\n        ::winrt::Microsoft::UI::Xaml::Controls::Button _myButton{nullptr};\n    };\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can see the accessor member functions for the <code>myButton<\/code> control. That&#8217;s why the syntax for accessing the object was <code>myButton().Content(box_value(L\"Clicked\"))<\/code>.<\/p>\n\n\n\n<div class=\"wp-block-uagb-inline-notice uagb-inline_notice__outer-wrap uagb-inline_notice__align-left uagb-block-0aae283b\"><h4 class=\"uagb-notice-title\">Impression: \u2b50\u2b50<\/h4><div class=\"uagb-notice-text\"><p>Not being able to edit the XAML in the visual designer is a huge drawback.<\/p><p>Familiarizing with WinRT concepts and structure needs some time.<\/p><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Building and Running<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Trying to build this project, I got the following error in the output window:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">DEP0100: Please ensure that target device has developer mode enabled. Could not check to see if Developer Mode is enabled on the local machine due to error 00000490. To learn more about Developer Mode, please visit https:\/\/go.microsoft.com\/fwlink\/?linkid=2128411<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The solution to this is to enable the <strong>Developer Mode<\/strong> from settings, <strong>Privacy &amp; Security &gt; For Developers<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/devmode.png\"><img loading=\"lazy\" decoding=\"async\" width=\"498\" height=\"278\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/devmode.png\" alt=\"\" class=\"wp-image-4466\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/devmode.png 498w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/devmode-300x167.png 300w\" sizes=\"auto, (max-width: 498px) 100vw, 498px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After this, building works and it also automatically downloads and installs missing components:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Creating a new clean layout...\nCopying files: Total 3 mb to layout...\nChecking whether required frameworks are installed...\nFramework: Microsoft.VCLibs.140.00.Debug.UWPDesktop\/X64, app package version 14.0.30704.0 is not currently installed.\nFramework: Microsoft.VCLibs.140.00.Debug\/X64, app package version 14.0.30704.0 is not currently installed.\nInstalling missing frameworks...\nRegistering the application to run from layout...\nDeployment complete (0:00:05.292). Full package name: \"17af30e1-10a4-4abe-8866-203638b1aa27_1.0.0.0_x64__60yvx6gbcw69r\"\n========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Running the app shows the following window:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/clickme.png\"><img loading=\"lazy\" decoding=\"async\" width=\"348\" height=\"538\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/clickme.png\" alt=\"\" class=\"wp-image-4467\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/clickme.png 348w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/clickme-194x300.png 194w\" sizes=\"auto, (max-width: 348px) 100vw, 348px\" \/><\/a><\/figure>\n\n\n\n<div class=\"wp-block-uagb-inline-notice uagb-inline_notice__outer-wrap uagb-inline_notice__align-left uagb-block-1153975d\"><h4 class=\"uagb-notice-title\">Impression: \u2b50\u2b50\u2b50\u2b50\u2b50<\/h4><div class=\"uagb-notice-text\"><p>Building and running was a seamless experience.<\/p><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Creating the demo app<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I want my demo app to have two text boxes: one for entering a Celsius value and one for Fahrenheit values. As you edit any of them, entering a value, the other should display the equivalent value. Here is how the UI is going to look:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;Window\n    x:Class=\"WinUIApp.MainWindow\"\n    xmlns=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation\"\n    xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\"\n    xmlns:local=\"using:WinUIApp\"\n    xmlns:d=\"http:\/\/schemas.microsoft.com\/expression\/blend\/2008\"\n    xmlns:mc=\"http:\/\/schemas.openxmlformats.org\/markup-compatibility\/2006\"\n    mc:Ignorable=\"d\">\n\n   &lt;Grid Margin=\"10\">\n      &lt;Grid.RowDefinitions>\n         &lt;RowDefinition Height=\"Auto\" \/>\n         &lt;RowDefinition Height=\"Auto\" \/>\n      &lt;\/Grid.RowDefinitions>\n      &lt;Grid.ColumnDefinitions>\n         &lt;ColumnDefinition Width=\"Auto\" \/>\n         &lt;ColumnDefinition Width=\"*\" \/>\n      &lt;\/Grid.ColumnDefinitions>\n\n      &lt;TextBlock Grid.Column=\"0\" Grid.Row=\"0\" Text=\"Celsius\" \/>\n      &lt;TextBox Grid.Column=\"1\" Grid.Row=\"0\" Name=\"txtCelsius\"\/>\n\n      &lt;TextBlock Grid.Column=\"0\" Grid.Row=\"1\" Text=\"Fahrenheit\" \/>\n      &lt;TextBox Grid.Column=\"1\" Grid.Row=\"1\" Name=\"txtFahrenheit\"\/>\n   &lt;\/Grid>\n&lt;\/Window>\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If I build and run it, it looks as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"265\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui1-700x265.png\" alt=\"\" class=\"wp-image-4471\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui1-700x265.png 700w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui1-300x114.png 300w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui1-768x291.png 768w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui1.png 779w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">What I need to do next is adding handlers. The designer does not work, but luckily, adding them from the Source Editor does work:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/addhandler.png\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"117\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/addhandler-700x117.png\" alt=\"\" class=\"wp-image-4472\" srcset=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/addhandler-700x117.png 700w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/addhandler-300x50.png 300w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/addhandler-768x128.png 768w, https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/addhandler.png 1148w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">This is the modified code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;TextBox Grid.Column=\"1\" Grid.Row=\"0\" Name=\"txtCelsius\" TextChanged=\"txtCelsius_TextChanged\"\/>\n&lt;TextBox Grid.Column=\"1\" Grid.Row=\"1\" Name=\"txtFahrenheit\" TextChanged=\"txtFahrenheit_TextChanged\"\/><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here is how the handlers look in the header and source file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ --- MainWindow.xaml.h ---\nnamespace winrt::WinUIApp::implementation\n{\n    struct MainWindow : MainWindowT&lt;MainWindow>\n    {\n        MainWindow();\n\n        int32_t MyProperty();\n        void MyProperty(int32_t value);\n\n        void txtCelsius_TextChanged(winrt::Windows::Foundation::IInspectable const&amp; sender, winrt::Microsoft::UI::Xaml::Controls::TextChangedEventArgs const&amp; e);\n        void txtFahrenheit_TextChanged(winrt::Windows::Foundation::IInspectable const&amp; sender, winrt::Microsoft::UI::Xaml::Controls::TextChangedEventArgs const&amp; e);\n    };\n}\n\n\/\/ --- MainWindow.xaml.cpp ---\nvoid winrt::WinUIApp::implementation::MainWindow::txtCelsius_TextChanged(winrt::Windows::Foundation::IInspectable const&amp; sender, winrt::Microsoft::UI::Xaml::Controls::TextChangedEventArgs const&amp; e)\n{\n}\n\nvoid winrt::WinUIApp::implementation::MainWindow::txtFahrenheit_TextChanged(winrt::Windows::Foundation::IInspectable const&amp; sender, winrt::Microsoft::UI::Xaml::Controls::TextChangedEventArgs const&amp; e)\n{\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Again, two things to notice:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The handlers are added outside the namespace from the original source (the one generate from the project template), which is inconsistent with the rest.<\/li><li>The code is generated with fully qualified names, even though the right <code>using namespace<\/code> directives where already declared, which is also inconsistent with the rest. Moreover, the result is cluttered code. These lines are so long it&#8217;s impossible to read.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here is my first attempt to implement the handler for the change of the Celsius value:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void MainWindow::txtCelsius_TextChanged(IInspectable const&amp; sender, TextChangedEventArgs const&amp; e)\n{\n   double celsius = std::stod(txtCelsius().Text().c_str());\n   double fahrenheit = 32 + 1.8 * celsius;\n   txtFahrenheit().Text() = std::to_wstring(fahrenheit);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This compiles but when executed does not work. The text is not set in the Fahrenheit box. Remember the <code>myButton().Content(box_value(L\"Clicked\"))<\/code> line? The text should probably be set with something like <code>Text(str)<\/code>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void MainWindow::txtCelsius_TextChanged(IInspectable const&amp; sender, TextChangedEventArgs const&amp; e)\n{\n   double celsius = std::stod(txtCelsius().Text().c_str());\n   double fahrenheit = 32 + 1.8 * celsius;\n   txtFahrenheit().Text(std::to_wstring(fahrenheit));\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This time it does work. But there are still some problems. The application crashes if you type a &#8211; (minus) or you write something in the Celsius field and then delete it all. So, the implementation to cover these looks as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void MainWindow::txtCelsius_TextChanged(IInspectable const&amp; sender, TextChangedEventArgs const&amp; e)\n{\n   winrt::hstring text = txtCelsius().Text();\n   if (!text.empty() &amp;&amp; text != L\"-\")\n   {\n      try\n      {\n         double celsius = std::stod(text.c_str());\n         double fahrenheit = 32 + 1.8 * celsius;\n         txtFahrenheit().Text(std::to_wstring(fahrenheit));\n      }\n      catch(...)\n      {\n         txtFahrenheit().Text(L\"\");\n      }\n   }\n   else\n   {\n      txtFahrenheit().Text(L\"\");\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The opposite formula is <code>C = (F - 32) \/ 1.8<\/code>. You can find the source code for the other handler in the attached zip archive.<\/p>\n\n\n\n<div class=\"wp-block-uagb-inline-notice uagb-inline_notice__outer-wrap uagb-inline_notice__align-left uagb-block-2c891461\"><h4 class=\"uagb-notice-title\">Impression: \u2b50\u2b50\u2b50<\/h4><div class=\"uagb-notice-text\"><p>Code generation is not at its best. Inconsistencies between the project templates and the generated code are obvious. Fully qualified names of components of the WinUI framework make the code hard to read.<\/p><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Adding more features<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To try to get a better feeling of the experience of working with the WinUI API, I decided do add some more features. For instance, the ability to toggle between a light mode and dark mode of the UI. The WinUI framework has a toggle button, represented by the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.xaml.controls.toggleswitch?view=winui-3.0\" title=\"ToggleSwitch\" target=\"_blank\" rel=\"noreferrer noopener\">ToggleSwitch<\/a> class. So, I added one to the top-right corner of the window:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;ToggleSwitch Grid.Column=\"1\" Grid.Row=\"0\" HorizontalAlignment=\"Right\"\n              Name=\"toggleMode\" Header=\"Mode\" \n              OnContent=\"Light\" OffContent=\"Dark\"\n              IsOn=\"True\"\n              Toggled=\"toggleMode_Toggled\"\/><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The implementation of the handler for the <code>Toggled<\/code> event should change the <code>Background<\/code> and <code>Foreground<\/code> of the window and its controls. It took me a while to figure out how to create brushes to set for the foreground and background properties of controls. The trouble is, the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.xaml.media.brush?view=winui-3.0\" title=\"Brush\" target=\"_blank\" rel=\"noreferrer noopener\">Brush<\/a> class in in the <code>winrt::Microsoft::UI::Xaml::Media<\/code> namespace, while the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.colors?view=winui-3.0\" title=\"Colors\" target=\"_blank\" rel=\"noreferrer noopener\">Colors<\/a> class is in the <code>winrt::Microsoft::UI<\/code> namespace. But there&#8217;s not all; there is also a <a href=\"https:\/\/docs.microsoft.com\/en-us\/uwp\/api\/windows.ui.colors?view=winrt-22000\" title=\"Colors\" target=\"_blank\" rel=\"noreferrer noopener\">Colors<\/a> class in the <code>winrt::Windows::UI<\/code> namespace. And that&#8217;s what I used first. However, that&#8217;s part of UWP and it works too, except that I got some errors. But first, here is my first attempt to implement the handler:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void MainWindow::toggleMode_Toggled(IInspectable const&amp; \/*sender*\/, RoutedEventArgs const&amp; \/*e*\/)\n{\n   if (!m_initialized) return;\n\n   ToggleMode(toggleMode().IsOn());\n}\n\nvoid MainWindow::ToggleMode(bool const light)\n{\n   auto bgColor = SolidColorBrush(\n      light ? \n      Colors::White() :\n      Colors::DarkGray());\n\n   auto txColor = SolidColorBrush(\n      light ?\n      Colors::Black() :\n      Colors::White());\n\n   rootGrid().Background(bgColor);\n\n   txtCelsius().Background(bgColor);\n   txtCelsius().Foreground(txColor);\n\n   txtFahrenheit().Background(bgColor);\n   txtFahrenheit().Foreground(txColor);\n\n   txtFahrenheit().Background(bgColor);\n   toggleMode().Foreground(txColor);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The compiler errors were the following:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">WinUIApp\\MainWindow.xaml.cpp(82,18): error C3779: 'winrt::Windows::UI::Colors::White': a function that returns 'auto' cannot be used before it is defined\nWinUIApp\\Generated Files\\winrt\\impl\\Windows.UI.2.h(172): message : see declaration of 'winrt::Windows::UI::Colors::White'\nWinUIApp\\MainWindow.xaml.cpp(83,18): error C3779: 'winrt::Windows::UI::Colors::Black': a function that returns 'auto' cannot be used before it is defined\nWinUIApp\\Generated Files\\winrt\\impl\\Windows.UI.2.h(42): message : see declaration of 'winrt::Windows::UI::Colors::Black'<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This means that the definition of the <code>White()<\/code> and <code>Black()<\/code> functions could not be found. So I was missing a header. Turned out I had to include the following in <code>pch.h<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include &lt;winrt\/Windows.UI.h><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The good part is that the file names and the namespaces have the same name. So if you&#8217;re looking to include the APIs from the <code>winrt::Microsoft::UI::Xaml::Controls<\/code> namespace, then you need to include the header <code>&lt;winrt\/Microsoft.UI.Xaml.Controls.h&gt;<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With these changes I could compile and run but the behavior was not really what I expected. I got a few more problems:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>could not find how to change the color of the host window. I had to settle for changing the background color of the root grid and its elements.<\/li><li>foreground and background colors of the text blocks are changed when you hover then cursor over them, and changing the text color of the toggle switch header did not work.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Since the plan was not to provide a perfect solution but something that works to some level, I decided to simplify it as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void MainWindow::ToggleMode(bool const light)\n{\n   auto bgColor = SolidColorBrush(\n      light ? \n      Colors::White() :\n      Colors::DarkGray());\n\n   rootGrid().Background(bgColor);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With these changes, the application looks as follows:<\/p>\n\n\n\n<figure class=\"wp-block-jetpack-image-compare\"><div class=\"juxtapose\" data-mode=\"horizontal\"><img loading=\"lazy\" decoding=\"async\" id=\"4478\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui2.png\" alt=\"\" width=\"558\" height=\"254\" class=\"image-compare__image-before\"\/><img loading=\"lazy\" decoding=\"async\" id=\"4479\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui3.png\" alt=\"\" width=\"558\" height=\"254\" class=\"image-compare__image-after\"\/><\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">And then I realized I was using the wrong <code>Colors<\/code> class, from UWP instead of WinUI. The change required only a swapping of namespaces, from <code>winrt::Windows::UI<\/code> to <code>winrt::Microsoft::UI<\/code>. Of course, this also made unnecessary the inclusion of the <code>&lt;winrt\/Windows.UI.h&gt;<\/code> header.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A second feature that I decided to add was displaying an icon representing a thermometer based on the entered temperature. A value over 4 degrees Celsius would show a warm\/hot temperature, one below that a freezing temperature. When no value is entered, there should be no icon displayed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This turned out to be a mess. Because WinUI 3 has many classes including the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.xaml.controls.image?view=winui-3.0\" title=\"Image\" target=\"_blank\" rel=\"noreferrer noopener\">Image<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.xaml.controls.imageicon?view=winui-3.0\" title=\"ImageIcon\">ImageIcon<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.xaml.controls.bitmapicon?view=winui-3.0\" title=\"BitmapIcon\" target=\"_blank\" rel=\"noreferrer noopener\">BitmapIcon<\/a><\/li><li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/winui\/api\/microsoft.ui.xaml.media.imaging.bitmapimage?view=winui-3.0\" title=\"BitmapImage\" target=\"_blank\" rel=\"noreferrer noopener\">BitmapImage<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">After a few tries, I ended up using an <code>Image<\/code> object:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;Image Grid.Column=\"1\" Grid.Row=\"3\" Name=\"imageThermo\" \n       HorizontalAlignment=\"Left\" Margin=\"5\"\n       Width=\"48\" Height=\"48\" \/><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I created a helper function to set the right image source to this control. This wasn&#8217;t easy either, but eventually I found what I was looking for within the docs for the class. My function looks as follows:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void MainWindow::DisplayThermometer(std::optional&lt;double> value)\n{\n   if (!value.has_value())\n   {\n      ImageSource src(nullptr);\n      imageThermo().Source(src);\n   }\n   else\n   {\n      BitmapImage img;\n      Windows::Foundation::Uri uri(\n         value.value() > 4 ? \n         L\"ms-appx:\/\/\/Assets\/hot48.png\" : \n         L\"ms-appx:\/\/\/Assets\/freezing48.png\");\n      img.UriSource(uri);\n\n      imageThermo().Source(img);\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This function needs to be invoked every time the temperature value changes:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void MainWindow::txtCelsius_TextChanged(IInspectable const&amp; \/*sender*\/, TextChangedEventArgs const&amp; \/*e*\/)\n{\n   winrt::hstring text = txtCelsius().Text();\n   if (!text.empty() &amp;&amp; text != L\"-\")\n   {\n      try\n      {\n         double celsius = std::stod(text.c_str());\n         double fahrenheit = 32 + 1.8 * celsius;\n         txtFahrenheit().Text(std::to_wstring(fahrenheit));\n\n         DisplayThermometer(celsius);\n      }\n      catch(...)\n      {\n         txtFahrenheit().Text(L\"\");\n         DisplayThermometer({});\n      }\n   }\n   else\n   {\n      txtFahrenheit().Text(L\"\");\n      DisplayThermometer({});\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Eventually, I got the result I was looking for. Here are a couple of screenshots:<\/p>\n\n\n\n<figure class=\"wp-block-jetpack-image-compare\"><div class=\"juxtapose\" data-mode=\"horizontal\"><img loading=\"lazy\" decoding=\"async\" id=\"4484\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui4.png\" alt=\"\" width=\"623\" height=\"326\" class=\"image-compare__image-before\"\/><img loading=\"lazy\" decoding=\"async\" id=\"4485\" src=\"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/ui6.png\" alt=\"\" width=\"623\" height=\"326\" class=\"image-compare__image-after\"\/><\/div><\/figure>\n\n\n\n<div class=\"wp-block-uagb-inline-notice uagb-inline_notice__outer-wrap uagb-inline_notice__align-left uagb-block-afa5d45d\"><h4 class=\"uagb-notice-title\">Impression: \u2b50\u2b50<\/h4><div class=\"uagb-notice-text\"><p>Based on my experience with WPF I though doing these would be relatively simple but ended up spending unexpectedly more time reading docs to figure out how to do it. Maybe I&#8217;m too harsh, but a combination of unhelpful documentation and similar APIs created too much confusion for me.<\/p><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Final words<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WinUI 3 is trumpeted as the next big thing in Windows development. When it comes to the C++ projection of the API, unfortunately, I&#8217;m not impressed. I personally don&#8217;t see this as the modern native library C++ Windows developers have been wishing for the past 12-15 years. Designing user interfaces must be done by hand in XAML, which I often do in WPF, but not having the designer means you don&#8217;t really know what you get at design time and that&#8217;s a huge drawback. The C++ API is cumbersome at best. Although I tried to browse through the framework source code, the experience was similar to trying to make a sense of long template error messages. Also, the generated code is not optimal as I explained earlier. Maybe in a few versions it will get better but for the time being it doesn&#8217;t look like something that I&#8217;ll be using. I think that time has shown WinRT and UWP were a mistake. WinUI, instead of starting from scratch, sweeps the dirt under the carpet. I think it&#8217;s another mistake and time will tell whether I&#8217;m right or wrong.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Windows UI Library 3, known shortly as WinUI 3, is a native UI framework that ships with the Windows App SDK. This is an SDK complementary to the Windows SDK, WPF, WinForms, and Win32. It provides a new unified set of APIs and tools that can be used to develop desktop apps on Windows 11 (as well as downwards to Windows 10, version 1809). I decided to have a look at what this framework provides and this post is written as I am trying it. To evaluate it, I&#8217;ll try to build a small application that does conversion between Celsius and Fahrenheit degrees as you type in a field.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[7,146,8,289],"tags":[451,459,625],"class_list":["post-4462","post","type-post","status-publish","format-standard","hentry","category-c","category-windows","category-windows-programming","category-winrt","tag-c","tag-windows","tag-winui"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.1.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Exploring the Windows UI Library 3 for C++ and building a simple demo application to understand the capabilities of the framework\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Marius Bancila\"\/>\n\t<meta name=\"keywords\" content=\"c++,windows,winui\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.1.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Marius Bancila&#039;s Blog | About code. Mostly on C++\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Unwrapping WinUI3 for C++\" \/>\n\t\t<meta property=\"og:description\" content=\"Exploring the Windows UI Library 3 for C++ and building a simple demo application to understand the capabilities of the framework\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-04-08T19:31:36+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-04-08T19:31:39+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Unwrapping WinUI3 for C++\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Exploring the Windows UI Library 3 for C++ and building a simple demo application to understand the capabilities of the framework\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#article\",\"name\":\"Unwrapping WinUI3 for C++\",\"headline\":\"Unwrapping WinUI3 for C++\",\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/platforms-winui3.png\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#articleImage\",\"width\":1578,\"height\":610},\"datePublished\":\"2022-04-08T21:31:36+02:00\",\"dateModified\":\"2022-04-08T21:31:39+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":11,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#webpage\"},\"articleSection\":\"C++, Windows, Windows Programming, WinRT, C++, Windows, WinUI\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"position\":2,\"name\":\"IT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"position\":3,\"name\":\"Software\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/windows-programming\\\/#listItem\",\"name\":\"Windows Programming\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/#listItem\",\"name\":\"IT\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/windows-programming\\\/#listItem\",\"position\":4,\"name\":\"Windows Programming\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/windows-programming\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/windows-programming\\\/winrt\\\/#listItem\",\"name\":\"WinRT\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/#listItem\",\"name\":\"Software\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/windows-programming\\\/winrt\\\/#listItem\",\"position\":5,\"name\":\"WinRT\",\"item\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/windows-programming\\\/winrt\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#listItem\",\"name\":\"Unwrapping WinUI3 for C++\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/windows-programming\\\/#listItem\",\"name\":\"Windows Programming\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#listItem\",\"position\":6,\"name\":\"Unwrapping WinUI3 for C++\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/category\\\/it\\\/software\\\/windows-programming\\\/winrt\\\/#listItem\",\"name\":\"WinRT\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/\",\"name\":\"Marius Bancila\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Marius Bancila\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#webpage\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/\",\"name\":\"Unwrapping WinUI3 for C++\",\"description\":\"Exploring the Windows UI Library 3 for C++ and building a simple demo application to understand the capabilities of the framework\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/2022\\\/04\\\/08\\\/unwrapping-winui3-for-cpp\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/author\\\/admin\\\/#author\"},\"datePublished\":\"2022-04-08T21:31:36+02:00\",\"dateModified\":\"2022-04-08T21:31:39+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/\",\"name\":\"Marius Bancila's Blog\",\"description\":\"About code. Mostly on C++\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mariusbancila.ro\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Unwrapping WinUI3 for C++","description":"Exploring the Windows UI Library 3 for C++ and building a simple demo application to understand the capabilities of the framework","canonical_url":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/","robots":"max-image-preview:large","keywords":"c++,windows,winui","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#article","name":"Unwrapping WinUI3 for C++","headline":"Unwrapping WinUI3 for C++","author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/mariusbancila.ro\/blog\/wp-content\/uploads\/2022\/04\/platforms-winui3.png","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#articleImage","width":1578,"height":610},"datePublished":"2022-04-08T21:31:36+02:00","dateModified":"2022-04-08T21:31:39+02:00","inLanguage":"en-US","commentCount":11,"mainEntityOfPage":{"@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#webpage"},"isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#webpage"},"articleSection":"C++, Windows, Windows Programming, WinRT, C++, Windows, WinUI"},{"@type":"BreadcrumbList","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/mariusbancila.ro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","position":2,"name":"IT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","position":3,"name":"Software","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/#listItem","name":"Windows Programming"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/#listItem","name":"IT"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/#listItem","position":4,"name":"Windows Programming","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/winrt\/#listItem","name":"WinRT"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/#listItem","name":"Software"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/winrt\/#listItem","position":5,"name":"WinRT","item":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/winrt\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#listItem","name":"Unwrapping WinUI3 for C++"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/#listItem","name":"Windows Programming"}},{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#listItem","position":6,"name":"Unwrapping WinUI3 for C++","previousItem":{"@type":"ListItem","@id":"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/winrt\/#listItem","name":"WinRT"}}]},{"@type":"Organization","@id":"https:\/\/mariusbancila.ro\/blog\/#organization","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","url":"https:\/\/mariusbancila.ro\/blog\/"},{"@type":"Person","@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author","url":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/","name":"Marius Bancila","image":{"@type":"ImageObject","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/a84dd2831d955c38355ddea55df4df260809b88f36408bc14fd4eab8f7f131c9?s=96&d=mm&r=g","width":96,"height":96,"caption":"Marius Bancila"}},{"@type":"WebPage","@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#webpage","url":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/","name":"Unwrapping WinUI3 for C++","description":"Exploring the Windows UI Library 3 for C++ and building a simple demo application to understand the capabilities of the framework","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mariusbancila.ro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/#breadcrumblist"},"author":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"creator":{"@id":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/#author"},"datePublished":"2022-04-08T21:31:36+02:00","dateModified":"2022-04-08T21:31:39+02:00"},{"@type":"WebSite","@id":"https:\/\/mariusbancila.ro\/blog\/#website","url":"https:\/\/mariusbancila.ro\/blog\/","name":"Marius Bancila's Blog","description":"About code. Mostly on C++","inLanguage":"en-US","publisher":{"@id":"https:\/\/mariusbancila.ro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Marius Bancila's Blog | About code. Mostly on C++","og:type":"article","og:title":"Unwrapping WinUI3 for C++","og:description":"Exploring the Windows UI Library 3 for C++ and building a simple demo application to understand the capabilities of the framework","og:url":"https:\/\/mariusbancila.ro\/blog\/2022\/04\/08\/unwrapping-winui3-for-cpp\/","article:published_time":"2022-04-08T19:31:36+00:00","article:modified_time":"2022-04-08T19:31:39+00:00","twitter:card":"summary","twitter:title":"Unwrapping WinUI3 for C++","twitter:description":"Exploring the Windows UI Library 3 for C++ and building a simple demo application to understand the capabilities of the framework"},"aioseo_meta_data":{"post_id":"4462","title":null,"description":"Exploring the Windows UI Library 3 for C++ and building a simple demo application to understand the capabilities of the framework","keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"aioseo-article-636965130181f","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-04-05 13:12:39","updated":"2025-12-12 07:57:11","seo_analyzer_scan_date":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"author_meta":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"featured_img":null,"jetpack_publicize_connections":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Marius Bancila","author_link":"https:\/\/mariusbancila.ro\/blog\/author\/admin\/"},"uagb_comment_info":11,"uagb_excerpt":"The Windows UI Library 3, known shortly as WinUI 3, is a native UI framework that ships with the Windows App SDK. This is an SDK complementary to the Windows SDK, WPF, WinForms, and Win32. It provides a new unified set of APIs and tools that can be used to develop desktop apps on Windows&hellip;","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/c\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/windows\/\" class=\"advgb-post-tax-term\">Windows<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/\" class=\"advgb-post-tax-term\">Windows Programming<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/winrt\/\" class=\"advgb-post-tax-term\">WinRT<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">Windows<\/span>","<span class=\"advgb-post-tax-term\">Windows Programming<\/span>","<span class=\"advgb-post-tax-term\">WinRT<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/winrt\/\" class=\"advgb-post-tax-term\">C++<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/winrt\/\" class=\"advgb-post-tax-term\">Windows<\/a>","<a href=\"https:\/\/mariusbancila.ro\/blog\/category\/it\/software\/windows-programming\/winrt\/\" class=\"advgb-post-tax-term\">WinUI<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">C++<\/span>","<span class=\"advgb-post-tax-term\">Windows<\/span>","<span class=\"advgb-post-tax-term\">WinUI<\/span>"]}},"comment_count":"11","relative_dates":{"created":"Posted 4 years ago","modified":"Updated 4 years ago"},"absolute_dates":{"created":"Posted on April 8, 2022","modified":"Updated on April 8, 2022"},"absolute_dates_time":{"created":"Posted on April 8, 2022 9:31 pm","modified":"Updated on April 8, 2022 9:31 pm"},"featured_img_caption":"","series_order":"","jetpack_shortlink":"https:\/\/wp.me\/pYNdv-19Y","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/comments?post=4462"}],"version-history":[{"count":15,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4462\/revisions"}],"predecessor-version":[{"id":4489,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/posts\/4462\/revisions\/4489"}],"wp:attachment":[{"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/media?parent=4462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/categories?post=4462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mariusbancila.ro\/blog\/wp-json\/wp\/v2\/tags?post=4462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}