This project is read-only.

Reviewing the code further below, can you pick out where the 2-pixel thick black border is being set? What about where the Composite is being defined with the text "Green" and "Green as grass"? Or where the highlight text color is set to Dark Green and highlight background to Khaki?

WPF Composites is designed with the intention of being fluent, easy to read, and easy to figure out. It can be slightly repetitive and/or verbose, but it is open source so you could rename methods or abstract things further? If "BeginComposite" is too long/wordy, re-name it "BeginC" ?

For ComboBoxes, WPF supports three different combinations of IsReadOnly and IsEditable. See details here:
For convenience, these are exposed via a new ComboStyles enum which is hopefully more explicit and intuitive?

    public enum ComboStyles
       NoTypeAheadButSelectableText = 1,
       TypeAheadButCannotSelectOrCopyText = 2, 
       TypeAheadSelectableButAcceptsAnyText = 3
Select a ComboStyle upon initializing the combo box.

Also, note that for TypeAhead purposes, I leverage the TextSearch.Text property which is built into WPF. Within ComboBoxArgs, you may specify an X and Y coordinate to use for the type-ahead search text (and in editable comboboxes, this is the text which will appear in the textbox.) So, basically if your composite has ten textblocks in it, you can tell it the specific one to use for type-ahead . . .

This search text is "bound" via an indirection: I store the search text X-Y as the ToolTip text and then bind this to TextSearch.Text on each individual Composite (as well as setting TextSearch.TextPath on the ComboBox itself.) This just appears to be a necessary workaround since I needed a property to bind to; for example:
(((Border)itemToAdd)).SetBinding(TextSearch.TextProperty, "ToolTip");
source.SetValue(TextSearch.TextPathProperty, "ToolTip");

Full example of coding up ComboBox with WPF Composites:

ComboBox cb1 = new ComboBox();
cb1.Initialize(142D, 57, ContainerType.Grid, 1, 1, true, 150D, ComboStyles.TypeAheadSelectableButAcceptsAnyText, Brushes.DarkGreen, Brushes.Khaki); //set CanContentScroll to true and ScrollViewer Height to 150        

FasterWPF.ContemporaryStyle.ApplyToScrollViewer(cb1, "LawnGreen", "Green", "ForestGreen");
cb1.SetCompositeGridDimensions<ComboBox>(2, 1, 93, GridUnitType.Pixel, 25, GridUnitType.Pixel);
cb1.BeginSettings<ComboBox>().SetItemBorderSettings<ComboBox>(90, 50, Brushes.Black, new Thickness(2)).EndSettings<ComboBox>();
cb1.SubscribeEventOnParent<ComboBox>("SelectionChanged", new SelectionChangedEventHandler(cb1_SelectionChanged));

cb1.BeginComposite<ComboBox>(cbGuid1).AddText<ComboBox>(0, 0, "Blue").AddText<ComboBox>(1, 0, "Blue as water.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

cb1.BeginComposite<ComboBox>(cbGuid2).AddText<ComboBox>(0, 0, "Red").AddText<ComboBox>(1, 0, "Red as apple.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

cb1.BeginComposite<ComboBox>(cbGuid3).AddText<ComboBox>(0, 0, "Green").AddText<ComboBox>(1, 0, "Green as grass.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

cb1.BeginComposite<ComboBox>(cbGuid4).AddText<ComboBox>(0, 0, "Orange").AddText<ComboBox>(1, 0, "Orange as pumpkin.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

cb1.BeginComposite<ComboBox>(cbGuid5).AddText<ComboBox>(0, 0, "Yellow").AddText<ComboBox>(1, 0, "Yellow as taxicab.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

cb1.BeginComposite<ComboBox>(cbGuid6).AddText<ComboBox>(0, 0, "Purple").AddText<ComboBox>(1, 0, "Purple as grape.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

cb1.BeginComposite<ComboBox>(cbGuid7).AddText<ComboBox>(0, 0, "Brown").AddText<ComboBox>(1, 0, "Brown as dirt.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

cb1.BeginComposite<ComboBox>(cbGuid8).AddText<ComboBox>(0, 0, "Black").AddText<ComboBox>(1, 0, "Black as midnight.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));

cb1.BeginComposite<ComboBox>(cbGuid9).AddText<ComboBox>(0, 0, "Silver").AddText<ComboBox>(1, 0, "Silver as lining.").EndComposite<ComboBox, ComboBoxArgs>(new ComboBoxArgs(1, 0));


Last edited Feb 10, 2013 at 5:24 AM by stagathome0069, version 16


No comments yet.