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)
} );