[Silverlight] Optimizing C1flexgrid cell borders

Source: Internet
Author: User
Tags silverlight

A justification for optimization

As shown, if you follow the C1flexgrid cell border setting, which is set for each cell's CellStyle borderthickness, you get the effect:

It is obvious to see that if two adjacent cells set the adjacent edge at the same time, it will look very coarse ... The reason is very simple, c1flexgrid is on the basis of the grid extension, and each cell is drawn through a nested layer of border processing, and then the landlord idle dt himself with a grid simulation of a simple C1flexgrid table, and then with border nested into, Set the border border, the effect is exactly the same, the overlap is thicker; Another problem is that C1flexgrid can set the Gridlinesbrush property to show the gray lines in the default box display (no cell borders are set immediately). But the problem is, in (1,0,0,0) cell settings, the right and bottom of the default line is gone, even though I do not want the cell right and bottom border, but you can not put the default rules of the line to lose ah ...

This for Virgo landlord, is simply intolerable defects ah, so the landlord on the reference C1flexgrid of the demo Project Excelbook 5.0 to do their own optimization processing, and the optimization applied to the continuous improvement of the imitation Excel extension C1flexgrid control.

Two optimization ideas

As you can see in Demo--excelbook 5.0, they have nested four layers of border in each cell's content perimeter to draw the top, bottom, left, and right borders of the cells and their colors:

1 //* * Overrides2  Public Override voidApply (Border bdr, Selectedstate selstate)3{4     Base. Apply (BDR, Selectedstate.none)5Applyborder (BDR, _bdrleft,NewThickness (_bdrthickness.left, 0, 0, 0))6Applyborder (BDR, _bdrtop,NewThickness (0, _bdrthickness.top, 0, 0))7Applyborder (BDR, _bdrright,NewThickness (0, 0, _bdrthickness.right, 0))8Applyborder (BDR, _bdrbottom,NewThickness (0, 0, 0, _bdrthickness.bottom))9}Ten voidApplyborder (Border bdr, Brush BR, Thickness t) One{ A     if(BR! =NULL&& T! = _thicknessempty) -{ -         //Create inner border thevar inner =NewBorder () -Inner. BorderThickness = t -Inner. BorderBrush = BR -  +         //Transfer content -var content = bdr. Child +Bdr. Child = Inner AInner. Child = Content at  -         //Transfer padding -Inner. Padding = bdr. Padding -Bdr. Padding = _thicknessempty -} -} in 
Excelcellstyle

The landlord is optimized according to this idea, each cell has a default BORDER--BDR, let it handle the C1flexgrid default frame display, that is, in one of the gray lines mentioned, and then nested two layers border, one is responsible for the right border, one is responsible for the bottom border, The reason is to not let the overlapping borders appear thick lines, so that all the cells are only responsible for handling their right and bottom borders, and the top border of the cell is responsible for the bottom box of the cell above it, the left border of the cell is responsible for the right border of the cell on the left side of it, so that when agreed, You can avoid the appearance of thick lines in the middle of adjacent cells.

Three optimization implementation

Define your own cell border settings in your custom CellStyle, as follows

Private Thickness _bdrthickness; //Cell border

The optimization is then implemented in the method apply that automatically applies the cell style:

1 // <summary>2 ///When you redraw cells, nested layer Two border are used to display the right and bottom borders respectively3 // </summary>4  Public Override voidApply (Border bdr, Selectedstate selstate)5{6     Base. Apply (BDR, Selstate)7     8     //Bottom Border9Border bottom =NewBorder ()TenBottom. BorderThickness =NewThickness (0, 0, 0, 1) OneBottom. BorderBrush = _bdrthickness.bottom = = 1 A?NewSolidColorBrush (Colors.black) -:NewSolidColorBrush (Color.FromArgb (0xFF, 0xe7, 0xe7, 0xe7)) -  the     //Right border -Border right =NewBorder () -Right. BorderThickness =NewThickness (0, 0, 1, 0) -Right. BorderBrush = _bdrthickness.right = = 1 +?NewSolidColorBrush (Colors.black) -:NewSolidColorBrush (Color.FromArgb (0xFF, 0xe7, 0xe7, 0xe7)) +  A     //left box and top border placed on outermost main border to set at     if(_bdrthickness.left = = 1 | | _bdrthickness.top = = 1) -{ -Bdr. BorderBrush =NewSolidColorBrush (Colors.black) -Bdr. BorderThickness =NewThickness (_bdrthickness.left, _bdrthickness.top, 0, 0) -} -     Else in{ -Bdr. BorderThickness =NewThickness (0, 0, 0, 0) to} +  -UIElement content = bdr. Child theBdr. Child = Bottom *Bottom. Child = Right $Right. Child = ContentPanax Notoginseng  -Right. Padding = bdr. Padding theBottom. Padding = _thicknessempty +Bdr. Padding = _thicknessempty A} the 

Finally, when you apply a cell style to a cellfactory in C1flexgrid, you take the _bdrthickness value of the cell border that you defined in CellStyle as the border value of border.

Of course, after optimization of the cell border of C1flexgrid, there is a principle when setting the cell border, that is, if you set the right and bottom border of the cell, it is OK to set the cell's _bdrthickness property directly. But if you set the left and top borders of the cell, you will have to give the corresponding cell a border to handle.

Well, finally look at the landlord to put the optimization scheme into the Imitation Excel extension C1flexgrid control effect bar.

This set of optimization program is based on the inspiration of the demo, the landlord before this has a set of their own optimization program, the landlord can see how busy DT, and later have time to put the package in.

Four Resources download

Copy Excel Extension C1flexgrid control: Http://files.cnblogs.com/files/memento/Memento.SLExcelSample.zip

(The project has been added to the previous article to achieve the column additions and deletions and cell merge Split function)

Please give more advice, thank you!

[Silverlight] Optimizing C1flexgrid cell borders

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.