Silverlight custom Layout container

Source: Internet
Author: User

The so-called layout containers in Silverlight are actuallyInherited fromPanelClassAnd then rewrite the two methods:

Measureoverride: Size of the calculated element to be rendered

Arrangeoverride: Rendering elements at specific locations

 

Demo:

Using system; using system. componentmodel; using system. windows; using system. windows. controls; using system. windows. threading; namespace layoutdemo {public class testpanel2: Panel {public testpanel2 () {} protected override size measureoverride (size availablesize) {foreach (uielement element in base. children) {element. measure (availablesize);} return base. measureoverride (availablesize);} protected Override size arrangeoverride (size finalsize) {Switch (this. ori) {Case orientation. horizontal: {double num = finalsize. height; foreach (uielement element in base. children) {num-= element. desiredsize. height; element. arrange (New rect (0.0, num, finalsize. width, element. desiredsize. height);} break;} case orientation. vertical: {double num2 = finalsize. width; foreach (uielement element in base. Children) {num2-= element. desiredsize. width; element. arrange (New rect (num2, 0.0, element. desiredsize. width, finalsize. height);} break;} return base. arrangeoverride (finalsize);} protected static void onlayoutchanged (dependencyobject sender, dependencypropertychangedeventargs ARGs) {testpanel2 base2 = sender as testpanel2; If (base2! = NULL) {base2.refleshupdate () ;}} public void refleshupdate () {double num = base. actualwidth. Equals (double. Nan )? Base. desiredsize. Width: Base. actualwidth; double num2 = base. actualheight. Equals (double. Nan )? Base. desiredsize. height: base. actualheight; this. arrangeoverride (new size (Num, num2);} public orientation Ori {get {return (orientation) getvalue (oriproperty);} set {setvalue (oriproperty, value );}} public static readonly dependencyproperty oriproperty = dependencyproperty. register ("Ori", typeof (orientation), typeof (testpanel), new propertymetadata (orientation. horizontal, onvaluechaged); P Rivate static void onvaluechaged (dependencyobject sender, dependencypropertychangedeventargs e) {testpanel2 Panel = sender as testpanel2; If (panel! = NULL) {panel. refleshupdate ();}}}}

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.