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.
Implements
Namespace: Syncfusion.UI.Xaml.CellGrid.Styles
Assembly: Syncfusion.SfCellGrid.WPF.dll
Syntax
public abstract class StyleInfoBase : Object, 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 support BeginUpdate, EndUpdate mechanism. This allows users to batch several operations on a style object into one transaction.
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
add_Changed(StyleChangedEventHandler)
Declaration
public void add_Changed(StyleChangedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
StyleChangedEventHandler | value |
add_Changing(StyleChangedEventHandler)
Declaration
public void add_Changing(StyleChangedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
StyleChangedEventHandler | value |
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 CachedStyleInfoSubObjectIdentity(this, sip);
}
Dispose()
Releases all resources used by the component.
Declaration
public void Dispose()
Dispose(Boolean)
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. |
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. |
GetSchema()
Not implemented and returns NULL.
Declaration
public XmlSchema GetSchema()
Returns
Type |
---|
System.Xml.Schema.XmlSchema |
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 |
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. |
remove_Changed(StyleChangedEventHandler)
Declaration
public void remove_Changed(StyleChangedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
StyleChangedEventHandler | value |
remove_Changing(StyleChangedEventHandler)
Declaration
public void remove_Changing(StyleChangedEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
StyleChangedEventHandler | value |
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. |
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 |