CppXAML
Loading...
Searching...
No Matches
Namespaces | Classes | Functions
cppxaml Namespace Reference

The main CppXAML namespace. More...

Namespaces

namespace  utils
 Various utilities.
 

Classes

struct  AppController
 AppController is responsible for coordinating XamlWindow instances, can extend their wndproc, and provides an opportunity to hook up event handlers once a XAML UI becomes live. More...
 
struct  SimpleNotifyPropertyChanged
 Helper base class to inherit from to have a simple implementation of INotifyPropertyChanged. More...
 
struct  TypedXamlEvent
 A default event handler that maps to Windows.Foundation.TypedEventHandler. More...
 
struct  XamlEvent
 A default event handler that maps to Windows.Foundation.EventHandler. More...
 
struct  XamlProperty
 Implements a simple property (without change notifications). More...
 
struct  XamlPropertyWithNPC
 Implements a property type with notifications. More...
 
struct  XamlWindow
 Implements an HWND based host for XAML Islands. You can create a XamlWindow from one of three overloads of XamlWindow::Make. More...
 

Functions

template<typename T >
 MakeContentControl (winrt::Windows::Foundation::IInspectable i)
 Create a XAML element of a class that derives from ContentControl
 
template<typename T >
 MakeContentControl (winrt::hstring v)
 Create a XAML element of a class that derives from ContentControl by wrapping a string as its content.
 
template<typename T >
 MakePanel (const std::initializer_list< cppxaml::xaml::UIElement > &elems)
 Creates a XAML element of a type that is a subclass of Panel.
 
template<typename C >
auto ContentDialog (C i)
 Creates a ContentDialog
 
auto StackPanel (const std::initializer_list< cppxaml::xaml::UIElement > &elems)
 Creates a StackPanel.
 
template<typename TElements >
 Grid (details::GridRows gr, cppxaml::details::GridColumns gc, TElements &&elems)
 Creates a Grid with the specified rows, columns, and children.
 
auto TextBox (std::wstring_view text=L"")
 Creates a TextBox
 
template<typename T , typename TItems >
 MakeItemsControl (const TItems &items)
 Creates a XAML element of a type that derives from ItemsControl
 
template<typename TItems >
auto AutoSuggestBox (const TItems &svs)
 Creates an AutoSuggestBox from a list of items.
 
 TextBlock (std::wstring_view text)
 Creates a TextBlock from its text content.
 
template<typename C >
auto Button (C c)
 Creates a Button.
 
auto FontIcon (std::wstring_view icon)
 Creates a FontIcon from a string.
 
auto FontIcon (uint32_t glyph)
 Creates a FontIcon from a glyph codepoint.
 
auto MenuFlyoutItem (std::wstring_view text)
 Creates a MenuFlyoutItem with the specified text.
 
template<typename... TMenuFlyoutItemBase>
auto MenuFlyout (TMenuFlyoutItemBase &&... items)
 Creates a MenuFlyout from a list of MenuFlyoutItems
 
template<typename TWindow >
void InitializeWithWindow (winrt::Windows::Foundation::IInspectable obj, TWindow w)
 Initializes an object with a window-like object.
 
bool InitializeWithWindow (winrt::Windows::Foundation::IInspectable obj, HWND hwnd)
 Initializes a FrameworkElement with an HWND.
 
void InitializeWithWindow (winrt::Windows::Foundation::IInspectable obj, const cppxaml::XamlWindow *xw)
 Initializes a FrameworkElement with the window represented by the XamlWindow or the XAML content root that the XamlWindow object is hosting.
 
template<typename TUIElement , typename TWindow >
void InitializeWithWindow (cppxaml::details::Wrapper< TUIElement > obj, TWindow w)
 
template<typename T = cppxaml::xaml::DependencyObject>
FindChildByName (cppxaml::xaml::DependencyObject d, std::wstring_view name)
 Finds a XAML element by name.
 
void InitializeWinUI (uint8_t minorVersion=8)
 Dynamically initializes WinUI 2. This API works on Windows 11 and newer. Adds the WinUI 2 framework package to the process's package graph. This enables unpackaged applications to use the stable (non-prerelease) WinUI 2 NuGet package.
 
void UninitializeWinUI ()
 Removes a reference to WinUI from the process's package graph.
 

Detailed Description

The main CppXAML namespace.

Function Documentation

◆ AutoSuggestBox()

template<typename TItems >
template< typename TItems > auto cppxaml::AutoSuggestBox ( const TItems &  svs)

Creates an AutoSuggestBox from a list of items.

Template Parameters
TItems
Parameters
svsa list of wstring_view to populate the control from.
Returns
cppxaml::details::Wrapper<cppxaml::xaml::Controls::AutoSuggestBox, TItems>

◆ Button()

template<typename C >
template< typename C > cppxaml::details::Wrapper< cppxaml::xaml::Controls::Button > cppxaml::Button ( c)

Creates a Button.

Template Parameters
CThe type of the content to initialize the button with.
Parameters
cThe content for the button, e.g. a string, a TextBlock, or a panel with some children, etc.
Returns

◆ ContentDialog()

template<typename C >
template< typename C > cppxaml::details::Wrapper< cppxaml::xaml::Controls::ContentDialog > cppxaml::ContentDialog ( i)

Creates a ContentDialog

Template Parameters
CType of list of child controls
Parameters
iThe list of child controls
Returns
cppxaml::details::Wrapper<cppxaml::xaml::Controls::ContentDialog>

◆ FindChildByName()

template<typename T = cppxaml::xaml::DependencyObject>
T cppxaml::FindChildByName ( cppxaml::xaml::DependencyObject  d,
std::wstring_view  name 
)

Finds a XAML element by name.

Template Parameters
TExpected type of the element - defaults to DependencyObject.
Parameters
dXAML element object.
nameThe name to search for.
Returns
The XAML element whose name matches the one specified as input.

◆ FontIcon() [1/2]

auto cppxaml::FontIcon ( std::wstring_view  icon)

Creates a FontIcon from a string.

Parameters
icon
Returns
cppxaml::details::Wrapper<cppxaml::xaml::Controls::FontIcon>

◆ FontIcon() [2/2]

auto cppxaml::FontIcon ( uint32_t  glyph)

Creates a FontIcon from a glyph codepoint.

Parameters
glyph
Returns
cppxaml::details::Wrapper<cppxaml::xaml::Controls::FontIcon>

◆ Grid()

template<typename TElements >
cppxaml::Grid ( details::GridRows  gr,
cppxaml::details::GridColumns  gc,
TElements &&  elems 
)

Creates a Grid with the specified rows, columns, and children.

The row and column definitions are specified with the same syntax.
This will be either an initializer list where each element is a height (a double, or the strings "Auto", or "N*" where N is an integer), or a string with the corresponding format.

Example usage:

auto grid = cppxaml::Grid({"40, *"}, {"Auto, Auto"}, {
{0, 0, cppxaml::TextBlock(L"first") },
{0, 1, cppxaml::TextBlock(L"second") },
{1, 0, cppxaml::TextBlock(L"third") },
{1, 1, cppxaml::TextBlock(L"fourth") },
}),
Grid(details::GridRows gr, cppxaml::details::GridColumns gc, TElements &&elems)
Creates a Grid with the specified rows, columns, and children.
Definition: Controls.h:510
TextBlock(std::wstring_view text)
Creates a TextBlock from its text content.
Definition: Controls.h:590
Parameters
grThe set of grid row definitions.
gcThe set of grid column definitions.
elemsA list of cppxaml::details::UIElementInGrid entries where each entry is a {rowNumber, columnNumber, myUIElement}
Returns

◆ InitializeWinUI()

void cppxaml::InitializeWinUI ( uint8_t  minorVersion = 8)

Dynamically initializes WinUI 2. This API works on Windows 11 and newer. Adds the WinUI 2 framework package to the process's package graph. This enables unpackaged applications to use the stable (non-prerelease) WinUI 2 NuGet package.

Parameters
minorVersionOptional minor version. Defaults to 8 (for 2.8)

◆ InitializeWithWindow() [1/4]

template<typename TUIElement , typename TWindow >
void cppxaml::InitializeWithWindow ( cppxaml::details::Wrapper< TUIElement >  obj,
TWindow  w 
)
Template Parameters
TUIElement
TWindow
Parameters
obj
w
Returns

◆ InitializeWithWindow() [2/4]

void cppxaml::InitializeWithWindow ( winrt::Windows::Foundation::IInspectable  obj,
const cppxaml::XamlWindow xw 
)

Initializes a FrameworkElement with the window represented by the XamlWindow or the XAML content root that the XamlWindow object is hosting.

Parameters
obj
xw

◆ InitializeWithWindow() [3/4]

bool cppxaml::InitializeWithWindow ( winrt::Windows::Foundation::IInspectable  obj,
HWND  hwnd 
)

Initializes a FrameworkElement with an HWND.

Parameters
obj
hwnd
Returns

◆ InitializeWithWindow() [4/4]

template<typename TWindow >
void cppxaml::InitializeWithWindow ( winrt::Windows::Foundation::IInspectable  obj,
TWindow  w 
)

Initializes an object with a window-like object.

Template Parameters
TWindowthe window-like type.
In system XAML, it must have a XamlRoot.
In WinUI 3, it must implement IWindowNative and have a Content property that exposes a XamlRoot (this will usually be Microsoft::UI::Xaml::Window).
Parameters
objThe object to attach to the window, e.g. a ContentDialog.
wThe window-like object.
Returns

◆ MakeContentControl() [1/2]

template<typename T >
cppxaml::MakeContentControl ( winrt::hstring  v)

Create a XAML element of a class that derives from ContentControl by wrapping a string as its content.

Template Parameters
TThe XAML type, e.g. Button.
Parameters
vThe string that will be set as the Content property.
Returns

◆ MakeContentControl() [2/2]

template<typename T >
cppxaml::MakeContentControl ( winrt::Windows::Foundation::IInspectable  i)

Create a XAML element of a class that derives from ContentControl

Template Parameters
TThe XAML type, e.g. Button. Defaults to void.
Parameters
iThe object that will be set as the Content property.
Returns

◆ MakeItemsControl()

template<typename T , typename TItems >
cppxaml::MakeItemsControl ( const TItems &  items)

Creates a XAML element of a type that derives from ItemsControl

Template Parameters
TThe XAML type, e.g. AutoSuggestBox.
TItemsThe type of the collection of items that might be used as seed to construct the control.
For example, this could be a std::vector<std::wstring> that is used to construct the Items collection for an AutoSuggestBox.
Defaults to void.
Parameters
itemsThe list of items to initialize the control with.
Returns

◆ MakePanel()

template<typename T >
cppxaml::MakePanel ( const std::initializer_list< cppxaml::xaml::UIElement > &  elems)

Creates a XAML element of a type that is a subclass of Panel.

Template Parameters
TThe XAML type.
Parameters
elemsThe list of UIElements
Returns

◆ MenuFlyout()

template<typename... TMenuFlyoutItemBase>
auto cppxaml::MenuFlyout ( TMenuFlyoutItemBase &&...  items)

Creates a MenuFlyout from a list of MenuFlyoutItems

Parameters
items
Returns
cppxaml::details::Wrapper<cppxaml::xaml::Controls::MenuFlyout>

◆ MenuFlyoutItem()

auto cppxaml::MenuFlyoutItem ( std::wstring_view  text)

Creates a MenuFlyoutItem with the specified text.

Parameters
text
Returns
cppxaml::details::Wrapper<cppxaml::xaml::Controls::MenuFlyoutItem>

◆ StackPanel()

auto cppxaml::StackPanel ( const std::initializer_list< cppxaml::xaml::UIElement > &  elems)

Creates a StackPanel.

Parameters
elemsThe list of child controls.
Returns
cppxaml::details::Wrapper<cppxaml::xaml::Controls::StackPanel>

◆ TextBlock()

cppxaml::TextBlock ( std::wstring_view  text)

Creates a TextBlock from its text content.

Parameters
textThe text for the control.
Returns

◆ TextBox()

auto cppxaml::TextBox ( std::wstring_view  text = L"")

Creates a TextBox

Parameters
textThe text to create the control from
Returns
cppxaml::details::Wrapper<cppxaml::xaml::Controls::TextBox>