This project is read-only.
Easy as 1-2-3-4-5

1. INITIALIZE - Initialize any Parent to wire it up for WPF Composites (automatically creating and storing the specified IComposite.) If you forget to Initialize then you'll likely receive a KeyNotFoundException.

myListBox.Initialize(413D, 450D, ContainerType.Grid, 5, 3);

2. IF NEEDED, SET COMPOSITE-RELATED SETTINGS - After initialization, some composites will require special setting methods to be called. These may include: SetCompositeCanvasSettings, SetCompositeDockPanelLastChildFill, SetCompositeUniformGridSettings, SetCompositeWrapPanelSettings, and SetCompositeGridDimensions.
For example, for parents that implement a GridComposite, set the dimensions (width, height, column width(s), grid unit type(s), row height(s), grid unit type(s)) for the Grid to be created as the foundation of each Composite . . .

myGrid.SetCompositeGridDimensions<Grid>(17, 4, 0.33, GridUnitType.Star, 0.13D, GridUnitType.Star);
NOTE: you can make a particular, individual Composite's Grid vary its Grid Dimensions by passing in its own Grid Settings to EndComposite when you create the Composite.

GridSettings compositeGridSettings = myDockPanel.CompositeGridDimensions<DockPanel>(
                428D, double.NaN, 1, 1, 428D, GridUnitType.Pixel, double.NaN, GridUnitType.Pixel);

. . .       .EndComposite(new DockArgs(Dock.Top), compositeGridSettings);

3. BEGINSETTINGS . . . ENDSETTINGS - Store any settings in the Parent to be applied to the children upon eventually adding them to the Composite during the next step BeginComposite . . . EndComposite. If you accidentally leave off the EndSetting call, then the settings simply will not be applied at all.

Here are two examples. Some setting methods are specific to a Type such as SetTextPadding, whereas, others leverage Generics to be more open and flexible, such as Set<K, T>( property, value ).
borderButton.BeginSettings<Border>().SetTextPadding<Border>(0, 0, new Thickness(4)).EndSettings<Border>();
horizPanel.BeginSettings<StackPanel>().Set<Border, StackPanel>("Margin", new Thickness(35, 0, 0, 0)).EndSettings<StackPanel>();
You can Set<K, T>( property, value ) by Type to apply a setting to all children of a certain Type K within the Composite, or by row-column position to apply a setting to a single child of Type K at a certain row-column within the Composite. The property must be valid on K and writeable.

You can also SetToCol in order to apply a setting to children by a row range within a single column or SetToRow in order to apply a setting to children by a column range within a single row. Again, the setting doesn't actually get applied until BeginComposite . . . EndComposite is eventually called.

.SetToCol<Label, ContentControl3D>(0, 4, 15, "VerticalAlignment", VerticalAlignment.Center)
.SetToRow<Label, ContentControl3D>(1, 0, 3, "Content", "example")
You will receive a DuplicateSettingException if you attempt to add the same setting more than once. However, you can override a setting applied by Type with the more fine-grained setting applied by row-column position.

NOTE: typically, you don't have to use the BeginSettings . . . EndSettings format. This is just for nice parallel construction, a syntax to parallel BeginComposite . . . EndComposite. Especially, if you are attempting to abstract away a subset of Set method calls, you may likely want to just call each Set on the Parent directly rather than in a BeginSettings . . . EndSettings pair; for example:
horizPanel.SetTextColorForLabel<StackPanel>(0, 4, Brushes.White);

4. SUBSCRIBE EVENTS - Subscribing events may occur at several levels (on the Parent, on the Composite, on the Child, or on the Container.) The level where you subscribe will determine when in the code you add your Subscription . . . so it could be (1) immediately right on the Parent, (2) in a Setting that will apply the subscription to the child upon adding it to the Composite, (3) right in the BeginComposite call, or even (4) separately after the Composite is created by getting a handle to it and appending a subscription.

5. BEGINCOMPOSITE . . . ENDCOMPOSITE - Create the Composite and add FrameworkElements to it by x-y coordinate. EndComposite occasionally takes an additional Args type that is used to define more properties related to the Composite as a whole; otherwise, this may just be set to null. Also, be aware that EndComposite returns a type of Border which is the root of the Composite itself (in case you need a handle to it.)

     .AddText<StackPanel>(0, 0, "Puerto Rico")
     .EndComposite<StackPanel, StackPanelArgs>(null);
NOTE: AddComposite (passing in a lambda) was the original syntax that I used. This legacy version may still be used if you prefer it or require it for abstracting away lines of code. I changed to BeginComposite . . . EndComposite just because there are developers who for one reason or another do not care for lambdas.

Last edited Mar 2, 2014 at 3:25 AM by stagathome0069, version 57


No comments yet.