page_type | languages | products | name | urlFragment | description | extendedZipContent | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
C# Windows Runtime Component WinUI Controls Sample |
csruntimecomponent |
Shows how to author a Windows Runtime Component in C# with WinUI controls and how to consume it from C++ and C#. |
|
This sample demonstrates how to author C# components with WinUI controls (User Control and Custom Control) using C#/WinRT, and how to consume these components from C++ and C# apps.
The sample solution includes the following application projects:
- CppApp (packaged C++ WinUI app)
- CppAppUnpackaged (unpackaged C++ WinUI app)
- CsApp (packaged C# WinUI app)
All the application projects have a project reference to the C# Windows Runtime component library project, WinUICsComponent. The C# component uses the Microsoft.Windows.CsWinRT NuGet package to generate a Windows Runtime Component with custom WinUI controls.
- See System requirements for Windows app development.
- Make sure that your development environment is set up correctly—see Install tools for developing apps for Windows 10 and Windows 11.
- Open the solution file (
.sln
) in Visual Studio. - Set one of the application projects as the startup project.
- From Visual Studio, either Start Without Debugging (Ctrl+F5) or Start Debugging (F5).