Differences between control and usercontrol in Silverlight

Source: Internet
Author: User

First, a UML diagram

 

In the simplest way, usercontrol is a subclass of control.

But in practice, they will be treated equally. Sometimes our control will let it inherit the control class directly, and sometimes it will inherit the usercontrol class directly.

 

Differences:

1. usercontrol is actually a combination of existing controls (Textbox, button...). Its function is to combine;

The main function of control is to make some controls with unique functions.

2. usercontrol is mainly for the interaction between some existing controls. For example, we want to have a page flip function, click the left button to flip the page, and right-click the page to flip or something, in this case, a usercontrol is used to implement a complex relationship between multiple controls. In such cases, usercontrol is generally used. For example, we define a myusercontrol to inherit from usercontrol to do such a thing.

The inheritance of control is mainly about the functions and appearance of the control.

 

3. usercontrol forms the appearance during design, while control forms the appearance during runtime.

4. If it inherits control, its template and style can be assigned a value to redefine its appearance and interaction mode. It only has one CS file, it only sets a value for its template or style at runtime, so that it has an appearance. Otherwise, it has no appearance.

But usercontrol is not allowed. It is defined by a XAML file and a CS file.

5. When a and B inherit from control and usercontrol, we can use a control to inherit from a, but we cannot use a usercontrol to inherit B.

Therefore, a thing that inherits control can be very active.

 

 

Application scenarios:

If you want to make a combination logic, a relatively high-level page will use usercontrol.

If you want to create a relatively independent control and want it to have different usage methods and appearances in different places, use control.

 

// Other information found on the Internet

• Relationship-usercontrol inherit control -- usercontrol inherits from control • difference-control: Visual is set in running time -- visible at runtime-usercontrol: visual is set in development time -- visible during design-control: mycontrol can be inherited -- can be inherited-usercontrol: myusercontrol can't be inherited -- cannot be inherited-control: C # Can't call visual element using this. '-- cannot pass this. to find the element-usercontrol: C # Can call visual element using 'this. '-- you can use this. to find the element • Usage-control: focus on data and feature in XAML -- Focus on data and features-usercontrol: Focus on visual -- Focus on logical combination display-control: template may be changed frequently -- template can be reset-usercontrol: Visual is merged by some controls stably-control: Using Data Binding -- bind-usercontrol: using code management -- Background Code

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.