ItemPolicy Class
A policy that specifies a set of rules in the designer.
Microsoft.Windows.Design.Policies.ItemPolicy
Microsoft.Windows.Design.Policies.SelectionPolicy
Assembly: Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)
The ItemPolicy type exposes the following members.
| Name | Description | |
|---|---|---|
|
Context | Gets the editing context for the designer. |
|
IsSurrogate | Gets a value indicating whether the policy is a surrogate policy. |
|
PolicyItems | Gets an enumeration of all items in the policy. |
| Name | Description | |
|---|---|---|
|
Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
|
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
|
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
|
GetSurrogateItems | Returns an optional set of surrogate items for this item. |
|
GetType | Gets the Type of the current instance. (Inherited from Object.) |
|
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
|
OnActivated | Called when a policy is activated. |
|
OnDeactivated | Called when the policy is deactivated. |
|
OnPolicyItemsChanged | Raises the PolicyItemsChanged event. |
|
ToString | Returns a string that represents the current object. (Inherited from Object.) |
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; } } }