Basics: Customizing WPF controls with Templates

Source: Internet
Author: User

With the release of the Windows Vista™ and microsoft®.net Framework 3.0, many new technologies have emerged for developers to learn, discuss, and use. New tools, libraries, and paradigms change the way in which managed applications are built, creating huge possibilities. The new monthly column we launch will introduce the basic techniques for developing applications. The industry experts you know will take turns to explore Windows®presentation Foundation, Windows Communication Foundation, and Windows Workflow Foundation. Here we go.

Customizing existing controls in Windows typically takes four steps. First you need to be inspired. Then research and exploration are needed. This process will inevitably be difficult. And the final discovery needs to be completely rewritten. Because it is difficult to access code that associates the visual part of a control with its functionality, it is often impossible to customize the control. This code is critical to the control, so you must accept it completely, or skip it completely and replace it.

Developers of Windows presentation Foundation (provided as part of the. NET Framework 3.0) have inevitably experienced the hardships of custom controls. They put forward a refreshing and powerful solution that we call "templates".

The Windows presentation Foundation template is not only simple but powerful, so I can quickly understand its concept. I quickly understood the Windows presentation Foundation style (which is often confusing with templates), but the template takes us more time to understand.

Each predefined control that has a visual appearance in Windows presentation Foundation also has a template that fully defines its appearance. This template is an object of type ControlTemplate (set to the Template property defined by the control class).

When you use the Windows presentation Foundation control in your application, you can replace the default template with a template of your own design. You can preserve the basic functionality of the control, including the handling of all keyboard and mouse actions, but you can set a completely different look for it. This is the meaning of "face-changing" (less elegant) when referring to Windows presentation Foundation controls. Controls have a default appearance, but this appearance is not the internal function of a fixed control.

It's not appropriate to write a template in code. It is easier to write with Extensible Application Markup Language (XAML), because templates can be represented in XAML and can be designed with the help of visual design tools. If you want to write a custom control that works like an existing Windows presentation Foundation control, but looks different, stop now! It is possible to get such a control using only one template.

The downloadable source code contains seven separate XAML files, which I'll discuss throughout the column. In the process of making this column, no C # code was compiled! If you have installed the. NET Framework 3.0 SDK, you can use my applications = Code + markup:a Guide to the Microsoft Windows presentation Foundati On "A similar program in the book XAMLPad or XAML cruncher edit these files.

Windows presentation Foundation supports other types of templates for displaying control content, but this column will only discuss objects of type ControlTemplate.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.