UserControl 类 (Windows.UI.Xaml.Controls) - Windows UWP applications

UserControl 类 (Windows.UI.Xaml.Controls) - Windows UWP applications

UserControl 类

参考

反馈

定义

命名空间:

Windows.UI.Xaml.Controls

重要

一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。

编辑

提供用于定义封装相关现有控件并提供其自己的逻辑的新控件的基类。

/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]

/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]

/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]

/// [Windows.UI.Xaml.Markup.ContentProperty(Name="Content")]

class UserControl : Control

[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]

[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]

[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]

[Windows.UI.Xaml.Markup.ContentProperty(Name="Content")]

public class UserControl : Control

Public Class UserControl

Inherits Control

singleContentElement

-or-

继承

Object

IInspectable

DependencyObject

UIElement

FrameworkElement

Control

UserControl

派生

Windows.UI.Xaml.Controls.Page

属性

ContractVersionAttribute

MarshalingBehaviorAttribute

ThreadingAttribute

ContentPropertyAttribute

Windows 要求

设备系列

Windows 10 (在 10.0.10240.0 中引入)

API contract

Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

以下示例演示如何创建 UserControl 并在应用中多次使用它。 第一个示例创建一个名为 NameReporter 的 UserControl,该控件要求提供人员的姓名,并将其报告给用户。

NameReporter 有多个 TextBlock 控件、两个 TextBox 控件和一个 Button。 用户在相应的 TextBox 中输入名字和姓氏,然后单击该按钮。 然后,该控件将显示一个消息框,其中包含用户输入的名字。

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

First Name:

Last Name:

Margin="6,4,4,4"/>

相关创作