TOC

This article is currently in the process of being translated into Korean (~19% done).

UserControls & CustomControls:

Introduction

지금까지 이 튜토리얼에서는 WPF 프레임워크에서 탑재된 내장 제어만 사용했습니다. 그들은 매우 유연하고 거의 모든 것을 하기 위해 스타일링되고 템플릿화 될 수 있기 때문에 매우 먼 길을 당신에게 줄 것입니다. 하지만 어느 시점에 이르면 당신 스스로 제어할 수 있는 방법을 만들어서 혜택을 얻을 수 있습니다. 다른 UI 프레임워크에서 이건상당히 번거로울 수 있지만, WPF는 UserControlsCustom controls가 작업을 수행하는 두 가지 방법을 제공하여 상당히 쉽게 만듭니다.

UserControls

A WPF UserControl inherits the UserControl class and acts very much like a WPF Window: You have a XAML file and a Code-behind file. In the XAML file, you can add existing WPF controls to create the look you want and then combine it with code in the Code-behind file, to achieve the functionality you want. WPF will then allow you to embed this collection of functionality in one or several places in your application, allowing you to easily group and re-use functionality across your application(s).

Custom controls

A Custom control is more low-level than a UserControl. When you create a Custom control, you inherit from an existing class, based on how deep you need to go. In many cases, you can inherit the Control class, which other WPF controls inherits from (e.g. the TextBox), but if you need to go even deeper, you can inherit the FrameworkElement or even the UIElement. The deeper you go, the more control you get and the less functionality is inherited.

The look of the Custom control is usually controlled through styles in a theme file, while the look of the User control will follow the look of the rest of the application. That also highlights one of the major differences between a UserControl and a Custom control: The Custom control can be styled/templated, while a UserControl can't.

Summary

Creating re-usable controls in WPF is very easy, especially if you take the UserControl approach. In the next article, we'll look into just how easy it is to create a UserControl and then use it in your own application.

This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!