KGy SOFT

ICommandState Interface

KGy SOFT Core Libraries Help
Represents the states of a command for a specific command binding. When a state value is set (eg. Enabled) it can be applied for all of the command sources. By default, no application occurs but this can be overridden if an ICommandStateUpdater is added to the binding by the ICommandBinding.AddStateUpdater method. For example, if the command sources are UI elements (eg. a button and a menu item), then the Enabled or any arbitrary state (eg. text, image, shortcut, etc.) can be applied to the sources as properties.
See the Remarks section for details.

Namespace:  KGySoft.ComponentModel
Assembly:  KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 5.0.0-rc.1
Syntax

public interface ICommandState : IDictionary<string, Object>, 
	ICollection<KeyValuePair<string, Object>>, IEnumerable<KeyValuePair<string, Object>>, 
	IEnumerable, INotifyPropertyChanged

The ICommandState type exposes the following members.

Properties

  NameDescription
Public propertyAsDynamic
Gets the state as a dynamic object so the states can be set by simple property setting syntax.
Public propertyCount (Inherited from ICollectionKeyValuePairString, Object.)
Public propertyEnabled
Gets or sets whether the command is enabled in the current binding.
Default value: .
Public propertyIsReadOnly (Inherited from ICollectionKeyValuePairString, Object.)
Public propertyItem
Gets or sets the element with the specified key.
(Inherited from IDictionaryString, Object.)
Public propertyKeys (Inherited from IDictionaryString, Object.)
Public propertyValues (Inherited from IDictionaryString, Object.)
Top
Methods

  NameDescription
Public methodAdd(T) (Inherited from ICollectionKeyValuePairString, Object.)
Public methodAdd(TKey, TValue) (Inherited from IDictionaryString, Object.)
Public methodClear (Inherited from ICollectionKeyValuePairString, Object.)
Public methodContains (Inherited from ICollectionKeyValuePairString, Object.)
Public methodContainsKey (Inherited from IDictionaryString, Object.)
Public methodCopyTo (Inherited from ICollectionKeyValuePairString, Object.)
Public methodGetEnumerator
Returns an enumerator that iterates through the collection.
(Inherited from IEnumerableKeyValuePairString, Object.)
Public methodRemove(TKey) (Inherited from IDictionaryString, Object.)
Public methodRemove(T) (Inherited from ICollectionKeyValuePairString, Object.)
Public methodTryGetValue
Gets the value associated with the specified key.
(Inherited from IDictionaryString, Object.)
Top
Events

  NameDescription
Public eventPropertyChanged
Occurs when a property value changes.
(Inherited from INotifyPropertyChanged.)
Top
Extension Methods

  NameDescription
Public Extension MethodAddRangeKeyValuePairString, Object (Defined by CollectionExtensions.)
Public Extension MethodAsThreadSafeKeyValuePairString, Object (Defined by CollectionExtensions.)
Public Extension MethodCreatePropertyBinding(String, String, Object)Overloaded.
Creates a special binding for the PropertyChanged event of the specified source, which allows to update the specified targetPropertyName in the targets, when the property of sourcePropertyName changes in the source.
(Defined by Command.)
Public Extension MethodCreatePropertyBinding(String, String, FuncObject, Object, Object)Overloaded.
Creates a special binding for the PropertyChanged event of the specified source, which allows to update the specified targetPropertyName in the targets, when the property of sourcePropertyName changes in the source.
(Defined by Command.)
Public Extension MethodForEachKeyValuePairString, Object
Similarly to the List<T>.ForEach method, processes an action on each element of an enumerable collection.
(Defined by EnumerableExtensions.)
Public Extension MethodGetRandomElementKeyValuePairString, Object(Boolean)Overloaded.
Gets a random element from the enumerable source using a new Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodGetRandomElementKeyValuePairString, Object(Random, Boolean)Overloaded.
Gets a random element from the enumerable source using a specified Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodCode exampleGetValueOrDefaultTActualValue(String, TActualValue)Overloaded.
Tries to get the typed value from a String-Object dictionary for the given key.
See the Examples section for some examples.
(Defined by DictionaryExtensions.)
Public Extension MethodGetValueOrDefaultTActualValue(String, TActualValue)Overloaded. (Defined by DictionaryExtensions.)
Public Extension MethodIndexOf(FuncObject, Boolean)Overloaded.
Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions.)
Public Extension MethodIndexOf(Object)Overloaded.
Searches for an element in the source enumeration.
(Defined by EnumerableExtensions.)
Public Extension MethodIndexOfKeyValuePairString, Object(FuncKeyValuePairString, Object, Boolean)Overloaded.
Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions.)
Public Extension MethodIndexOfKeyValuePairString, Object(KeyValuePairString, Object)Overloaded.
Searches for an element in the source enumeration.
(Defined by EnumerableExtensions.)
Public Extension MethodIsNullOrEmptyOverloaded.
Determines whether the specified source is  or empty (has no elements).
(Defined by EnumerableExtensions.)
Public Extension MethodIsNullOrEmptyKeyValuePairString, ObjectOverloaded.
Determines whether the specified source is  or empty (has no elements).
(Defined by EnumerableExtensions.)
Public Extension MethodShuffleKeyValuePairString, ObjectOverloaded.
Shuffles an enumerable source (randomizes its elements) using a new Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodShuffleKeyValuePairString, Object(Int32)Overloaded.
Shuffles an enumerable source (randomizes its elements) using the provided seed with a new Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodShuffleKeyValuePairString, Object(Random)Overloaded.
Shuffles an enumerable source (randomizes its elements) using a specified Random instance.
(Defined by EnumerableExtensions.)
Public Extension MethodToCircularListKeyValuePairString, Object (Defined by EnumerableExtensions.)
Public Extension MethodTryAdd(Object, Boolean, Boolean)Overloaded.
Tries to add the specified item to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryAddKeyValuePairString, Object(KeyValuePairString, Object, Boolean, Boolean)Overloaded.
Tries to add the specified item to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryAddRange(IEnumerable, Boolean, Boolean)Overloaded.
Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryAddRangeKeyValuePairString, Object(IEnumerableKeyValuePairString, Object, Boolean, Boolean)Overloaded.
Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryClear(Boolean, Boolean)Overloaded.
Tries to remove all elements from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryClearKeyValuePairString, Object(Boolean, Boolean)Overloaded.
Tries to remove all elements from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryGetElementAt(Int32, Object, Boolean, Boolean)Overloaded.
Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryGetElementAtKeyValuePairString, Object(Int32, KeyValuePairString, Object, Boolean, Boolean)Overloaded.
Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsert(Int32, Object, Boolean, Boolean)Overloaded.
Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsertKeyValuePairString, Object(Int32, KeyValuePairString, Object, Boolean, Boolean)Overloaded.
Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsertRange(Int32, IEnumerable, Boolean, Boolean)Overloaded.
Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryInsertRangeKeyValuePairString, Object(Int32, IEnumerableKeyValuePairString, Object, Boolean, Boolean)Overloaded.
Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemove(Object, Boolean, Boolean)Overloaded.
Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveKeyValuePairString, Object(KeyValuePairString, Object, Boolean, Boolean)Overloaded.
Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveAt(Int32, Boolean, Boolean)Overloaded.
Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveAtKeyValuePairString, Object(Int32, Boolean, Boolean)Overloaded.
Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveRange(Int32, Int32, Boolean, Boolean)Overloaded.
Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions.)
Public Extension MethodTryRemoveRangeKeyValuePairString, Object(Int32, Int32, Boolean, Boolean)Overloaded.
Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions.)
Public Extension MethodTryReplaceRange(Int32, Int32, IEnumerable, Boolean, Boolean)Overloaded.
Tries to remove count amount of items from the target at the specified index, and to insert the specified collection at the same position. The number of elements in collection can be different from the amount of removed items.
(Defined by EnumerableExtensions.)
Public Extension MethodTryReplaceRangeKeyValuePairString, Object(Int32, Int32, IEnumerableKeyValuePairString, Object, Boolean, Boolean)Overloaded.
Tries to remove count amount of items from the target at the specified index, and to insert the specified collection at the same position. The number of elements in collection can be different from the amount of removed items.
(Defined by EnumerableExtensions.)
Public Extension MethodTrySetElementAt(Int32, Object, Boolean, Boolean)Overloaded.
Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Public Extension MethodTrySetElementAtKeyValuePairString, Object(Int32, KeyValuePairString, Object, Boolean, Boolean)Overloaded.
Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions.)
Top
Remarks

The Enabled state, which is also predefined as a property, has a special function. By setting the Enabled property the execution of the command can be disabled or enabled.

If a binding has no updaters, then the states are not synchronized back to the sources.

A state updater can be added to a binding by the ICommandBinding.AddStateUpdater method. Multiple updaters can be added so if the first one cannot apply a state entry, then the second one will be used as a fallback and so on.

If state entries represent properties on the source you can add the PropertyCommandStateUpdater to the ICommandBinding so changing the Enabled, Text, Image, Shortcut, etc. state entries will change the same properties on the command sources as well.

Tip Tip
See the Remarks section of the ICommand interface for details and examples about commands.
See Also

Reference