Spread Windows Forms 8.0 Product Documentation > Developer's Guide > Understanding the Underlying Models > Finding More Details on the Sheet Models > Understanding the Style Model |
The style model includes appearance settings, whether determined in the Spread Designer, or set as properties in the Properties List or as inherited by a custom skin for a whole sheet or by a custom style for individual cells. For more information on appearance settings for a sheet, refer to Creating a Custom Skin for a Sheet and Applying a Skin to a Sheet. For more information on appearance settings for a cell, refer to Creating and Applying a Style for Cells.
Understanding the style model involves understanding these topics:
The style model includes the cell types as well. The various cell types determine the appearance of a cell in several ways. For more information about the various cell types, refer to Customizing Interaction with Cell Types.
Refer to the DefaultSheetStyleModel class for more information on the style model in general and the methods in particular.
For more details, refer to the BaseSheetStyleModel class, the DefaultSheetStyleModel class, and the ISheetStyleModel interface.
The appearance settings may be set from any of the following classes in the FarPoint Spread namespace that represent shortcut objects:
They also may be set from any of these classes in the FarPoint Spread namespace that affect style:
Properties that correspond to StyleInfo properties are stored in the style model through the ISheetStyleModel interface. Style properties can be set for a cell, row (column index -1), column (row index -1), or the entire model (column and row index -1). Properties that are NOT set in a cell are inherited from the row setting, or the column setting if the row has no setting, or the model default if the column also has no setting. The default is exposed through the DefaultStyle property (SheetView.DefaultStyle, ColumnHeader.DefaultStyle, and RowHeader.DefaultStyle). If you set or get a style property using Rows.Default or Rows[-1] or Columns.Default or Columns[-1], then you will actually be setting or getting the DefaultStyle property. This is because Column and Row always use row index -1 and column index -1 when accessing the style model, respectively, and so using a column index or a row index of -1 will be setting or getting the model default.
The order of inheritance is described to a certain extent in Object Parentage. Here is a list of the style properties that are included in the style model, which are basically the members of the StyleInfo class and affect the appearance or style of a cell:
To use the underlying style model, use the methods of the style model for that sheet, specifically the GetDirectInfo method and SetDirectInfo method, and the settings in the StyleInfo object. "Direct" in the style model means "not composite" or "not inherited." SetDirectInfo sets the style properties that have been set for the specified cell, column, or row directly and does not return any settings that are set for higher levels (such as the entire model), while GetCompositeInfo gives the style properties "composed" or "merged" into one StyleInfo object that contains all the settings that are used to paint and edit the cell, column, or row, including any inherited settings.
The style properties for a cell can be composited or merged from the Cell, Row, Column, SheetView, and parent NamedStyle objects. This code snippet illustrates the order of inheritance of a composited style:
Setting StyleName replaces the style in the style model with the NamedStyle having the specified name. This has the effect of changing the settings of all of the style-related properties, including ParentStyleName (which wraps StyleInfo.Parent). Any previous setting for style-related properties like BackColor, Font, Border, or ParentStyleName are overwritten when you set StyleName. All of these properties are already set in the NamedStyle object, and it would not make sense to change these properties on you just because you assigned the NamedStyle to a cell, column, row or alternating row. The named style is expected to already be set up the way you want it to be. If this includes the named style having a parent NamedStyle, then you should have that parent set already when you assign it with StyleName, or you should assign it separately using a reference to the NamedStyle object (this has the same effect as setting ParentStyleName after setting StyleName). Keep in mind that after you have set StyleName, all cells where you have used that name are sharing the same NamedStyle object, and any changes that you make to one of those cells will also be changing all of the other cells sharing the same named style.
C# |
Copy Code
|
---|---|
NamedStyle test_parent = new NamedStyle("test_parent"); test_parent.BackColor = Color.Red; test.ForeColor = Color.White; FpSpread1.NamedStyles.AddRange(new NamedStyle[] {test_parent, test}); FpSpread1.Sheets(0).Columns(0).BackColor = Color.Blue; FpSpread1.Sheets(0).Rows(0).CellType = new NumberCellType(); FpSpread1.Sheets(0).Cells(0,0).StyleName = "test"; FpSpread1.Sheets(0).Cells(1,0).StyleName = "test"; |
This code creates two NamedStyle objects with a parent-child relationship, then sets some properties on the styles and adds them to the NamedStyleCollection in the Spread component. Then the background color for the first column is set to blue and the cell type for the first row is set to Number, and the first cells in the first two rows are both set to use the NamedStyle named "test." The result is that the cells in the first column are blue, except for the cells in the first two rows, which are red because the "test" style inherits the red background color from its parent NamedStyle. The parent style overrides the inherited setting for the column.
The cell type for the first cell is Number, since there is cell type set in either NamedStyle object. There is a cell type set in the first row which is inherited by all cells in the row. The cell type for the second cell is General since there is no cell type setting for the cell, row, or column. The default cell type for the sheet is General. For more information on inheritance of style settings, refer to Object Parentage.
The FormatInfo strings in a saved XML file are DateTimeFormatInfo or NumberFormatInfo objects that store the format of the data. These are created in the style model when a General cell is edited, if the style model implements IParseFormatSupport. These format objects allow the cells to display the data in the same format that was used to enter it. The General cell type parses the string into a number or DateTime, and generates the IFormatProvider and format string necessary to render the data as it was entered. If you use TextCellType instead of GeneralCellType, then it works the same as the Edit cells did in the ActiveX FarPoint Spread, and no FormatInfo is stored in the style model, but the data entered into the cells is always treated as text.