Application = code + markup Chapter 5-7

Source: Internet
Author: User

The5ChapterStackpanelAndWrappanel

WPFDesigned panelPanelPut space and other elements on the panel.LayoutLayout.

Logical tree of the class:

Frameworkelement
Panel (abstract class)
Canvas
Dockpanel
Grid
Stackpanel
Uniformgrid
Wrappanel

1)Method for retrieving elements:

FrameworkelementOfFindnameMethod to retrieve all elements under the root node:

ButtonBTN = findname ("Buttonname")As Button;

UseChildrenIndex:

Grid. Children [5]; //Returned uielement type

Grid. Children. indexof (BTN );//Returns the index value of the BTN element. If the value does not exist, the value is-1.

You can use the event processor to obtain the object that generates the event in two ways:

ButtonBTN = senderAs Button;//Use the first parameter

ButtonBTN = E. SourceAs Button;//Use the second parameter

AboveCodeCorresponding:

BTN. Click + = buttonclick;

And

VoidButtonclick (ObjectSender,RoutedeventargsE ){}

The event processor is not used.BTN. Click + = buttonclickMethod for eachButtonAdd events instead of using:

Addhandler (Button. Clickevent,New Routedeventhandler(Buttonclick ));

At this time,SenderYesWindowObject, which meansWindowMonitors all its child elementsClickAndE. SourceIt is still the clicked button object.

Of course, you can also make allButtonBearerStackpanelFor monitoring:

Stack. addhandler (Button. Clickevent,New Routedeventhandler(Buttonclick ));

At this time,SenderYesStackpanelObject.

2) UseWrappanelGenerallyScrollviewer:

Scrollviewer scroll =   New Scrollviewer ();
Content = Scroll;
Wrappanel wrap =   New Wrappanel ();
Scroll. Content = Wrap;

3)ForScrollviewerIs a composite control, the arrow of its scroll bar endpoint, isRepeatbutton, This button also hasClickEvent. ThereforeScrollviewerOfClickMethod, to determineE. SourceIs the transformation successful:

Button BTN = E. Source As Button;

If (BTN ! =   Null )
{
//Do something
}

4) Put many elements in a limited space.Scrollviewer,WPFRecommendedViewbox:

Viewbox View =   New Viewbox ();
Content = View;
View. Child = Grid;

6thChapterStackAndWrap

1)Gridsplitter

GridsplitterDerived fromThumb, Can only be used inGridAnd specifyRowAndColumnLocation(And rows and columnsSPAN):

Gridsplitter split =   New Gridsplitter ();
Split. Width =   6 ;
Grid. Children. Add (split );
Grid. setcolumn (split, 2 );
Grid. setrow (split, 1 );

GridsplitterThe same cell can be shared with other elements, which causes the occlusion problem-the later elements appear in front. Therefore, you need to setMarginTo avoid overlap:

Split. Margin =New Thickness(10 );

GenerallyGridsplitterIt is reasonable to span the whole row or the whole column:

Grid. Setrowspan (split, 3 );

Grid. Setcolumnspan (split, 3 );

GenerallyGridsplitterPut them in one or more cells.

2)Uniformgrid

SimilarGridThe difference is that,UniformgridAll rows are equal to width, and all columns are high. You can simply set them as follows:

Uniformgrid unigrid =   New Uniformgrid ();
Unigrid. Rows =   2 ;
Unigrid. Columns =   3 ;

UniformgridThere is no affiliated attribute to specify a position for its internal elements. The index value can only be increased in sequence based on the order of adding elements.

Unigrid. Children. Add (BTN );

The7Chapter

1)PolygonUsage:

PolygonPoly =New Polygon();

Poly. Points =New Pointcollection();

Newly createdPolygonObject, itsPointsThe property isNull. Add a seriesPointHere:

Poly. Points. Add (New Point(0, 0 ));

Poly. Points. Add (New Point(1, 1 ));

Another method is to directly addPointArray:

Poly. Points =   New Pointcollection ( New Point []
{
NewPoint (0,0),
NewPoint (1,1)
} );

 

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.