Class StyleInfoBase
Provides a wrapper object for the StyleInfoStore object with type safe access to all properties stored in the style object.
Style objects provide a very user friendly way to modify data. It is very much like in Excel VBA. For example, to change the bold setting for a cell, you simply call grid[5,2].Font.Bold = True.
Inheritance
Implements
Inherited Members
Namespace: Syncfusion.Styles
Assembly: Syncfusion.Shared.Base.dll
Syntax
public abstract class StyleInfoBase : ShouldSerializeBasedPersisterType, ICustomTypeDescriptor, IDisposable, IStyleInfo, ISupportInitialize, IFormattable, IConvertible, IXmlSerializable
Remarks
The StyleInfoBase is a wrapper around the StyleInfoStore. It provides type safe accessor properties to modify data of the underlying data store and can hold temporary information about the style object that does not need to be persisted.
In Essential Grid for the example, the GridStyleInfo class holds extensive identity information about a style object such as cached base styles, row and column index, a reference to the grid model, and more. This is all the information that can be discarded when the style is no longer used (because maybe the cell is not visible anymore). Only the StyleInfoStore part needs to be kept alive.
Style objects only exist temporarily and will be created as a weak reference in a volatile data store. Once Garbage Collection kicks in smart style objects that are not referenced any more will be garbage collected. The volatile data cache can also be cleared manually.
Because Style objects know their identity they can notify their owner of changes or load base style information when the user interacts with the style object. This allows you to make changes to a style object directly, such as Cell.Font.Bold = True;
Style objects support property inheritance from parent styles, e.g. in a grid a cell can inherit properties from a parent row, column, table or a collection of names styles in a base styles map.
Style objects support subobjects. Subobjects can support inheritance (e.g. a Font.Bold can be inherited). Immutable subobjects like BrushInfo don't support inheritance of individual properties.
StyleInfoStore allows you to register any number of properties but keeps the data very memory efficient. Only properties that are actually used for a style object will be allocated for an object. The StyleObjectStore handles the storage of the object. For short integers, enums and Boolean values, the data will be stored in a BitVector32 structure to save even more memory.
Programmers can derive their own style classes from StyleInfoSubObjectBase and add type-safe (and intellisense) supported custom properties to the style class. If you write, for example, your own SpinButton class that needs individual properties, simply add a �CellSpinButtonInfo� class as subobject. If you derive CellSpinButtonInfo from StyleInfoSubObjectBase, your new object will support property inheritance from base styles.
Style objects can be written into a string (see ToString(String, IFormatProvider)) and later be recreated using the ParseString(String) method. When writing the string you have the option to show default values (use the �d� format). Subobjects will be identified with a dot �.�, e.g. �Font.Bold�
Style object support several operations how to combine information from two styles. Style operations include: apply changes, apply initialized properties, override initialized properties, exclude properties. See the ModifyStyle(IStyleInfo, StyleModifyType) method.
Style objects integrate with System.Windows.Forms.PropertyGrid. The property grid displays values that belong to a style object in bold. Values that are inherited from parent styles will be displayed as default values. The user can select several cells in a grid and the MergeStyle(IStyleInfo) operation will show common settings in the property grid as bold.
Style objects support BeginUpdate, EndUpdate mechanism. This allows users to batch several operations on a style object into one transaction.
Examples
The following example shows how you can use the GridFontInfo class in Essential Grid:
standard.Font.Facename = "Helvetica";
model[1, 3].Font.Bold = true;
string faceName = model[1, 3].Font.Facename; // any cell inherits standard style
Console.WriteLIne(faceName); // will output "Helvetica"
Console.WriteLIne(model[1, 3].Font.Bold); // will output "true"
Console.WriteLIne(model[1, 3].Font.HasFaceName); // will output "False"
Constructors
StyleInfoBase()
Overloaded. Initializes a new style object with no identity and data initialized.
Declaration
protected StyleInfoBase()
StyleInfoBase(StyleInfoIdentityBase, StyleInfoStore)
Initalizes a new StyleInfoBase object and associates it with an existing StyleInfoStore and StyleInfoIdentityBase.
Declaration
protected StyleInfoBase(StyleInfoIdentityBase identity, StyleInfoStore store)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoIdentityBase | identity | A StyleInfoIdentityBase that holds the identity for this StyleInfoBase. |
StyleInfoStore | store | A StyleInfoStore that holds data for this object. All changes in this style object will be saved in the StyleInfoStore object. |
StyleInfoBase(StyleInfoIdentityBase, StyleInfoStore, Boolean)
Initalizes a new StyleInfoBase object and associates it with an existing StyleInfoStore and StyleInfoIdentityBase.
Declaration
protected StyleInfoBase(StyleInfoIdentityBase identity, StyleInfoStore store, bool cacheValues)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoIdentityBase | identity | A StyleInfoIdentityBase that holds the identity for this StyleInfoBase. |
StyleInfoStore | store | A StyleInfoStore that holds data for this object. All changes in this style object will be saved in the StyleInfoStore object. |
System.Boolean | cacheValues | if set to |
StyleInfoBase(StyleInfoStore)
Initalizes a new StyleInfoBase object and associates it with an existing StyleInfoStore.
Declaration
protected StyleInfoBase(StyleInfoStore store)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoStore | store | A StyleInfoStore that holds data for this object. All changes in this style object will be saved in the StyleInfoStore object. |
Properties
CacheValues
Gets or sets a value indicating whether this instance should cache values for resolved base style properties.
Declaration
public bool CacheValues { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Identity
Gets / sets the identity information for the current StyleInfoBase.
Declaration
public StyleInfoIdentityBase Identity { get; set; }
Property Value
Type |
---|
StyleInfoIdentityBase |
IsChanged
Indicates whether any properties for this object have changed since it was applied last time.
Declaration
public bool IsChanged { get; }
Property Value
Type |
---|
System.Boolean |
IsEmpty
Indicates whether the style is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type |
---|
System.Boolean |
Store
The StyleInfoStore object that holds all the data for this style object.
Declaration
public StyleInfoStore Store { get; }
Property Value
Type |
---|
StyleInfoStore |
Updating
Indicates whether BeginUpdate() was called for this object.
Declaration
public bool Updating { get; }
Property Value
Type |
---|
System.Boolean |
WeakReferenceChangedListeners
A list of listeners that will be referenced using a WeakReference. The listeners must implement the IStyleChanged interface. When this style object OnStyleChanged(StyleInfoProperty) method is called it will then loop through all objects in this list and call each objects StyleChanged(StyleChangedEventArgs) method.
Declaration
public List<WeakReference> WeakReferenceChangedListeners { get; }
Property Value
Type |
---|
System.Collections.Generic.List<System.WeakReference> |
Methods
BeginInit()
Suspends raising Changed events until EndInit() is called and will not change the IsChanged state of this object.
Declaration
public void BeginInit()
BeginUpdate()
Suspends raising Changed events until EndUpdate() is called.
Declaration
public void BeginUpdate()
ClearCache()
Clears the cache.
Declaration
public void ClearCache()
CopyFrom(IStyleInfo)
Copies properties from another style object. This method raises Changing and Changed notifications if the other object differs. (ModifyStyle does not raise these events).
Declaration
public void CopyFrom(IStyleInfo istyle)
Parameters
Type | Name | Description |
---|---|---|
IStyleInfo | istyle | The style object to be applied on the current object. |
CreateSubObjectIdentity(StyleInfoProperty)
Override this method to create a product-specific identity object for a sub object.
Declaration
public virtual StyleInfoSubObjectIdentity CreateSubObjectIdentity(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip |
Returns
Type | Description |
---|---|
StyleInfoSubObjectIdentity | An identity object for a subobject of this style. |
Examples
The following code is an example how Essential Grid creates GridStyleInfoSubObjectIdentity:
public override StyleInfoSubObjectIdentity CreateSubObjectIdentity(StyleInfoProperty sip)
{
return new GridStyleInfoSubObjectIdentity(this, sip);
}
Dispose()
Releases all resources used by the component.
Declaration
public void Dispose()
Dispose(Boolean)
Releases all resources used by the component.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
EndInit()
Declaration
public void EndInit()
EndUpdate()
Suspends raising Changed events and if changes were made before the EndUpdate() call, it will raise a changed notification immediately.
Declaration
public void EndUpdate()
Equals(Object)
Indicates whether two style objects are equal. Identity is left out with this comparison, only the data (Store) are compared.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The other style object to compare the current object with. |
Returns
Type | Description |
---|---|
System.Boolean | True if both objects have equal data; false otherwise. |
Overrides
EqualsObject(Object, Object)
Compares two objects for equality. Works also with NULL references.
Declaration
protected static bool EqualsObject(object obj1, object obj2)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj1 | The first object to compare. |
System.Object | obj2 | The second object to compare. |
Returns
Type | Description |
---|---|
System.Boolean | True if both objects are equal. |
GetDefaultStyle()
Override this method to return a default style object for your derived class.
Declaration
protected abstract StyleInfoBase GetDefaultStyle()
Returns
Type | Description |
---|---|
StyleInfoBase | A default style object. |
Remarks
You should cache the default style object in a static field.
GetDefaultStyleInfoStore(StyleInfoProperty)
Locates the StyleInfoStore in the list of base styles that provides a specific property.
Declaration
protected virtual StyleInfoStore GetDefaultStyleInfoStore(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | Identifies the property to look for. |
Returns
Type | Description |
---|---|
StyleInfoStore | The style store object that has the specified property. |
GetDefaultValue(StyleInfoProperty)
Gets the default value from a base style.
Declaration
protected virtual object GetDefaultValue(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | The sip. |
Returns
Type |
---|
System.Object |
GetHashCode()
Returns a hash code which is based on values inside the Store.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | An integer hash code. |
Overrides
GetShortValue(StyleInfoProperty)
Queries the System.Int16 value for the specified property that has been initialized for the current object or locates it in a base style.
Declaration
public short GetShortValue(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | A StyleInfoProperty that identifies the property to operate on. |
Returns
Type |
---|
System.Int16 |
GetValue(StyleInfoProperty)
Queries the value for the specified property that has been initialized for the current object or locates it in a base style.
Declaration
public object GetValue(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | A StyleInfoProperty that identifies the property to operate on. |
Returns
Type |
---|
System.Object |
HasValue(StyleInfoProperty)
Indicates whether the specified property has been initialized for the current object.
Declaration
public bool HasValue(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | A StyleInfoProperty that identifies the property to operate on. |
Returns
Type |
---|
System.Boolean |
InheritStyle(IStyleInfo, StyleModifyType)
Applies changes to a style object as specified with StyleModifyType.
Declaration
public virtual void InheritStyle(IStyleInfo istyle, StyleModifyType mt)
Parameters
Type | Name | Description |
---|---|---|
IStyleInfo | istyle | The style object to be applied on the current object. |
StyleModifyType | mt |
IntGetDefaultStyleInfo(StyleInfoProperty)
Locates the base style that has the specified property and returns its instance.
Declaration
protected virtual StyleInfoBase IntGetDefaultStyleInfo(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | Identifies the property to look for. |
Returns
Type | Description |
---|---|
StyleInfoBase | The style object that has the specified property. |
IsSubset(IStyleInfo)
Compares all properties with another style object and indicates whether the current set of initialized properties is a subset of the other style object.
Declaration
public bool IsSubset(IStyleInfo istyle)
Parameters
Type | Name | Description |
---|---|---|
IStyleInfo | istyle | The other style to compare with. |
Returns
Type | Description |
---|---|
System.Boolean | True if this style object is a subset of the other style object. |
IsValueModified(StyleInfoProperty)
Indicates whether the specified property has been modified for the current object.
Declaration
protected bool IsValueModified(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | A StyleInfoProperty that identifies the property to operate on. |
Returns
Type |
---|
System.Boolean |
MergeStyle(IStyleInfo)
Merges two styles. Resets all properties that differ among the two style objects and keeps only those properties that are equal.
Declaration
public void MergeStyle(IStyleInfo istyle)
Parameters
Type | Name | Description |
---|---|---|
IStyleInfo | istyle | The other style object this style object should merge with. |
ModifyStyle(IStyleInfo, StyleModifyType)
Applies changes to a style object as specified with StyleModifyType.
Declaration
public virtual void ModifyStyle(IStyleInfo istyle, StyleModifyType mt)
Parameters
Type | Name | Description |
---|---|---|
IStyleInfo | istyle | The style object to be applied on the current object. |
StyleModifyType | mt | The actual operation to be performed. |
OnStyleChanged(StyleInfoProperty)
Notifies the associated identity object that a specific property was changed and raises a Changed event.
Declaration
protected virtual void OnStyleChanged(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | Identifies the property to look for. |
OnStyleChanging(StyleInfoProperty)
Notifies the associated identity object that a specific property will be changed and raises a Changing event.
Declaration
protected virtual void OnStyleChanging(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | Identifies the property to look for. |
ParseString(String)
Parses a given string and applies it's results to affected properties in this style object.
Declaration
public void ParseString(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The string to be parsed. |
Remarks
ParseString(String) consumes strings previously generated with a ToString(String, IFormatProvider) method call.
ReadXml(XmlReader)
Deserializes the contents of this object from an XML stream.
Declaration
public void ReadXml(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlReader | reader | Represents the XML stream. |
ResetValue(StyleInfoProperty)
Marks the specified property as uninitialized for the current object.
Declaration
public void ResetValue(StyleInfoProperty sip)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | A StyleInfoProperty that identifies the property to operate on. |
SetStore(StyleInfoStore)
Sets the StyleInfoStore object that holds all the data for this style object.
Declaration
protected void SetStore(StyleInfoStore store)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoStore | store |
SetValue(StyleInfoProperty, Int16)
Initializes the System.Int16 value for the specified property.
Declaration
public void SetValue(StyleInfoProperty sip, short value)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | A StyleInfoProperty that identifies the property to operate on. |
System.Int16 | value | The value to be saved for the property. |
SetValue(StyleInfoProperty, Object)
Overloaded. Initializes the value for the specified property.
Declaration
public void SetValue(StyleInfoProperty sip, object value)
Parameters
Type | Name | Description |
---|---|---|
StyleInfoProperty | sip | A StyleInfoProperty that identifies the property to operate on. |
System.Object | value | The value to be saved for the property. |
ToString()
Overloaded. Creates a formatted string for this style object. This string can later be consumed by ParseString(String).
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string with formatted style information. |
Overrides
Remarks
Style objects can be formatted into a string that can be consumed by ParseString(String) to recreate style information.
When writing the string, you have the option to show default values (use the �d� format).
Subobjects will be identified with a period ".", e.g. "Font.Bold".
ToString(String)
Creates a formatted string for this style object. This string can later be consumed by ParseString(String). You can specify "d" as format if you want to write out default values inherited from a base style.
Declaration
public string ToString(string format)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | Use "d" if default values should be included; "G" and NULL are default. |
Returns
Type | Description |
---|---|
System.String | A string with formatted style information. |
Remarks
Style objects can be formatted into a string that can be consumed by ParseString(String) to recreate style information.
When writing the string you have the option to show default values (use the "d" format) or not.
Subobjects will be identified with a period ".", e.g. "Font.Bold".
ToString(String, IFormatProvider)
Creates a formatted string for this style object. This string can later be consumed by ParseString(String). You can specify "d" as format if you want to write out default values inherited from a base style.
Declaration
public string ToString(string format, IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.String | format | Use "d" if default values should be included; "G" and NULL are default. |
System.IFormatProvider | provider | An System.IFormatProvider to be used for the ToString(String, IFormatProvider) operation. Can be NULL. |
Returns
Type | Description |
---|---|
System.String | A string with formatted style information. |
Remarks
Style objects can be formatted into a string that can be consumed by ParseString(String) to recreate style information.
When writing the string you have the option to show default values (use the "d" format) or not.
Subobjects will be identified with a period ".", e.g. "Font.Bold".
WriteXml(XmlWriter)
Serializes the contents of this object into an XML stream.
Declaration
public void WriteXml(XmlWriter writer)
Parameters
Type | Name | Description |
---|---|---|
System.Xml.XmlWriter | writer | Represents the XML stream. |
Events
Changed
Occurs when a property in the style object or in a sub object is changed.
Declaration
public event StyleChangedEventHandler Changed
Event Type
Type |
---|
StyleChangedEventHandler |
Changing
Occurs before a property in the style object or in a sub object is changed.
Declaration
public event StyleChangedEventHandler Changing
Event Type
Type |
---|
StyleChangedEventHandler |
Explicit Interface Implementations
IConvertible.GetTypeCode()
Declaration
TypeCode IConvertible.GetTypeCode()
Returns
Type |
---|
System.TypeCode |
IConvertible.ToBoolean(IFormatProvider)
Declaration
bool IConvertible.ToBoolean(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.Boolean |
IConvertible.ToByte(IFormatProvider)
Declaration
byte IConvertible.ToByte(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.Byte |
IConvertible.ToChar(IFormatProvider)
Declaration
char IConvertible.ToChar(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.Char |
IConvertible.ToDateTime(IFormatProvider)
Declaration
DateTime IConvertible.ToDateTime(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.DateTime |
IConvertible.ToDecimal(IFormatProvider)
Declaration
decimal IConvertible.ToDecimal(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.Decimal |
IConvertible.ToDouble(IFormatProvider)
Declaration
double IConvertible.ToDouble(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.Double |
IConvertible.ToInt16(IFormatProvider)
Declaration
short IConvertible.ToInt16(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.Int16 |
IConvertible.ToInt32(IFormatProvider)
Declaration
int IConvertible.ToInt32(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.Int32 |
IConvertible.ToInt64(IFormatProvider)
Declaration
long IConvertible.ToInt64(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.Int64 |
IConvertible.ToSByte(IFormatProvider)
Declaration
sbyte IConvertible.ToSByte(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.SByte |
IConvertible.ToSingle(IFormatProvider)
Declaration
float IConvertible.ToSingle(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.Single |
IConvertible.ToString(IFormatProvider)
Declaration
string IConvertible.ToString(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.String |
IConvertible.ToType(Type, IFormatProvider)
Declaration
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.Type | conversionType | |
System.IFormatProvider | provider |
Returns
Type |
---|
System.Object |
IConvertible.ToUInt16(IFormatProvider)
Declaration
ushort IConvertible.ToUInt16(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.UInt16 |
IConvertible.ToUInt32(IFormatProvider)
Declaration
uint IConvertible.ToUInt32(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.UInt32 |
IConvertible.ToUInt64(IFormatProvider)
Declaration
ulong IConvertible.ToUInt64(IFormatProvider provider)
Parameters
Type | Name | Description |
---|---|---|
System.IFormatProvider | provider |
Returns
Type |
---|
System.UInt64 |