For an applicationProgramControls are the building blocks for building user interfaces. They have interactive features, such as text boxes, buttons, and list boxes. Nevertheless,WPFIt is also unusual that it does not directly depend on its appearance. ManyGuiThe framework requires the designer to write a custom control. InWPFThis is not necessary: Embedded content and templates provide simple and powerful solutions. Only when the required control does not exist in the existing nested control does it need to be re-developed.
ManyWPFThe user interface element is not a control. For example, some shapes:Rectangle,EllipseThey do not have any internal behavior, but just an appearance.
Figure3-1Shows how to adapt a control to a program. As you can see, the visible part of the control is provided by its template, not the control itself. This control is not completely separated from its appearance. Of course, the control uses these appearances to provide information to users. In addition, because these appearances are all visible to users, they will be real-time targets for any user input. This means that although these appearances can be replaced, these replicas have specific responsibilities. There is a contract between the control and its appearance. Template to replace the appearance of the control.5Chapter.
Figure3-1
you may be familiar with MVC ( Model View Controller ) concept. This is a way to design an interactive system. Previously, MVC there are already several ways to explain. But broadly speaking, it often splits the design into objects that represent the underlying data ( Model ), display Data Objects ( View ) to manage user input and management and View interaction object ( controller ).
Although the control makes itself visible to the user through the appearanceAPI(See figure3-1Left) to make the service effective to developers. Controls provide commands to provide supported operations. For example, a text box provides commands for cutting, copying, and pasting. Controls provide the attribute concept, which provides a way to modify the behavior or appearance. When an important event occurs, such as receiving external input, the control is activated.Event. Finally, some functions are passedMethodExposed externally. Select commands, attributes, and events as they are easy to use in Markup Language and supported by some design tools. However, there are still some situations where these controls must be in the backgroundCodeThe method is the most suitable at this time.APIRepresentation.
Of course, developers and designers are not the only people who use controls. The control must respond to the user at the same time, so let's take a look atWPF.