Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 2.07 KB

usercontrol.md

File metadata and controls

45 lines (30 loc) · 2.07 KB
-api-id -api-type
T:Windows.UI.Xaml.Controls.UserControl
winrt class

Windows.UI.Xaml.Controls.UserControl

-description

Provides the base class for defining a new control that encapsulates related existing controls and provides its own logic.

-xaml-syntax

<UserControl ...>
  singleContentElement
</UserControl>
-or-
<UserControl .../>

-remarks

Note that UserControl does not manifest the value of its property in its control template. Instead, set the Background of the root element inside the UserControl. For more info, see Remarks in Control.Background.

-examples

The following examples demonstrate creating a UserControl and using it multiple times in an app. This first example creates a UserControl called NameReporter that asks for a name of a person, and reports it back to the user. NameReporter has several TextBlock  controls, two TextBox controls, and a Button. The user enters a first and last name into the appropriate TextBox, and then clicks the button. The control then displays a message box with the name that the user entered.

[!code-xaml1]

[!code-csharp2]

[!code-vb2]

Note

The src prefix in this XAML references the app itself and the UserControlExample code namespace within it. That is where the NameReporter control is defined. For more info on XAML prefixes, see XAML namespaces and namespace mapping.

[!code-xaml3]

-see-also

Control