This topic has not yet been rated - Rate this topic

ItemPolicy Class

A policy that specifies a set of rules in the designer.

System.Object
  Microsoft.Windows.Design.Policies.ItemPolicy
    Microsoft.Windows.Design.Policies.SelectionPolicy

Namespace:  Microsoft.Windows.Design.Policies
Assembly:  Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)
public abstract class ItemPolicy

The ItemPolicy type exposes the following members.

  Name Description
Protected method ItemPolicy Initializes a new instance of the ItemPolicy class.
Top
  Name Description
Protected property Context Gets the editing context for the designer.
Public property IsSurrogate Gets a value indicating whether the policy is a surrogate policy.
Public property PolicyItems Gets an enumeration of all items in the policy.
Top
  Name Description
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetSurrogateItems Returns an optional set of surrogate items for this item.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnActivated Called when a policy is activated.
Protected method OnDeactivated Called when the policy is deactivated.
Protected method OnPolicyItemsChanged Raises the PolicyItemsChanged event.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public event PolicyItemsChanged Occurs when the policy changes.
Top

Derive from the abstract ItemPolicy class to provide an association between a set of items and corresponding feature providers.

Use policies to discover extensibility features on items that are running in the designer. Policies are used by tools, adorners, and other areas of the designer that are extensible. The SelectionPolicy class is an example of policy that monitors selection changes and raises the PolicyItemsChanged event when selection changes. The designer handles change events for all running policies and takes appropriate action. In the case of SelectionPolicy, the designer queries for the set of active tasks that should be available and the set of adorners that should be visible on the design surface.

A single instance of a policy type is activated when the designer discovers it in metadata. Policies last for the life of the designer, and are never deactivated unless the designer itself is disposed. If you have a policy that holds a reference to process-global resources, implement the OnDeactivated method, which is called when the policy manager terminates.

A surrogate policy offers an alternative set of items that are used to locate feature providers. Surrogate policies are most often used by control containers that offer additional tasks and adorners on their children. In this scenario, the container offers a surrogate policy in which the GetSurrogateItems method returns the parent of the item provided.

The following code example shows how to implement a custom surrogate policy for the primary selection. For a full code listing, see How to: Create a Surrogate Policy.


// The DockPanelPolicy class implements a surrogate policy that
// provides container semantics for a selected item. By using 
// this policy, the DemoDockPanel container control offers 
// additional tasks and adorners on its children. 
class DockPanelPolicy : PrimarySelectionPolicy 
{
    public override bool IsSurrogate 
    {
        get 
        { 
            return true;
        }
    }

    public override IEnumerable<ModelItem> GetSurrogateItems(ModelItem item) 
    {
        ModelItem parent = item.Parent;

        if (parent != null)
        {
            yield return parent;
        }
    }
}


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ