How to associate UIElements with an AppWindow in WinUI3

hasechon 60 Reputation points
2023-08-06T08:52:28.9466667+00:00

What I want to do:

I want to add UI elements to an AppWindow in my WinUI3 desktop application using the Windows App SDK and C++.

The problem I am having:

I followed the documentation to create a new window for my desktop application with the AppWindow class.

Show multiple views with AppWindow However, I am having difficulty associating UI elements with the new window. Unlike with the Windows.UI.Xaml.Hosting.ElementCompositionPreview class, the Microsoft.UI.Xaml.Hosting.ElementCompositionPreview class does not have a SetAppWindowContent() method. Therefore, I cannot associate UIContents with the newly created appWindow. I am hoping for a simplified explanation of how to set an element on a newly created window. I would also like to know if it is possible to set a Window element other than the MainWindow or a Page element.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
869 questions
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,912 questions
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 12,731 Reputation points Microsoft External Staff
    2023-08-10T07:03:46.1133333+00:00

    Hello @hasechon,

    The Show multiple views with AppWindow document refers to Windows.UI.Xaml.Hosting.ElementCompositionPreview which you should use.

    Also

    Note AppWindow is currently in preview. This means you can submit apps that use AppWindow to the Store, but some platform and framework components are known to not work with AppWindow (see Limitations).


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.