Creating user controls
WinUI, like Windows Forms, supports the option to create user controls, which is a way to reuse UI components across an entire application. A user control is structured like a page – it has an XAML file, which contains existing XAML controls, and a code-behind file, which includes the logic. For example, let's say that your application offers the option to start a search. You can create a user control specific for this task, which groups together the UI (TextBox
to write the search term, Button
to start the search, and so on) and the logic required to perform a search across your data.
An important difference between WinUI and Windows Forms is the way you expose properties. Typically, a user control exposes one or more properties to allow customization when you add it to a specific page of your application. For example, the search box might have a different title based on the page where it's placed. As such, the title can't be hardcoded...