The documentation Host a standard WinRT XAML control in a C++ desktop (Win32) app describes how to use WinRT XAML control, but Microsoft.WinUI2 is not supported for now.
If you want to use Tabview
in a desktop application, it is recommended that you use the WinUI3 project.
How to add Win32 tab control in XAML island?
You can refer to this document Create a Tab Control in the Main Window.
I tested the code, and it can be used in XAML island.
//#include "CommCtrl.h"
//#pragma comment(lib,"Comctl32.lib")
RECT rcClient;
INITCOMMONCONTROLSEX icex;
TCITEM tie;
int i;
TCHAR achTemp[256]; // Temporary buffer for strings.
// Initialize common controls.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icex);
// Get the dimensions of the parent window's client area, and
// create a tab control child window of that size. Note that g_hInst
// is the global instance handle.
GetClientRect(WindowHandle(), &rcClient);
HWND hwndTab = CreateWindow(WC_TABCONTROL, L"",
WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
0, 0, rcClient.right, rcClient.bottom,
WindowHandle(), NULL, m_instance, NULL);
if (hwndTab == NULL)
{
return NULL;
}
// Add tabs for each day of the week.
tie.mask = TCIF_TEXT | TCIF_IMAGE;
tie.iImage = -1;
wchar_t lpWStr[32] = { 0 };
wsprintfW(lpWStr, L"TAB");
tie.pszText = lpWStr;
for (i = 0; i < 7; i++)
{
// Load the day string from the string resources. Note that
// g_hInst is the global instance handle.
if (TabCtrl_InsertItem(hwndTab, i, &tie) == -1)
{
DestroyWindow(hwndTab);
}
}
Thank you,
Junjie