Dela via


ItemPolicy Class

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

Namespace:  Microsoft.Windows.Design.Policies
Assembly:  Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)

Syntax

'Declaration
Public MustInherit Class ItemPolicy
'Usage
Dim instance As ItemPolicy
public abstract class ItemPolicy
public ref class ItemPolicy abstract
public abstract class ItemPolicy

Remarks

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.

Examples

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
    Inherits PrimarySelectionPolicy

    Public Overrides ReadOnly Property IsSurrogate() As Boolean  
        Get 
            Return True 
        End Get 
    End Property 

    Public Overrides Function GetSurrogateItems( _
        ByVal item As Microsoft.Windows.Design.Model.ModelItem) _
        As System.Collections.Generic.IEnumerable( _
        Of Microsoft.Windows.Design.Model.ModelItem)

        Dim parent As ModelItem = item.Parent

        Dim e As New System.Collections.Generic.List(Of ModelItem)

        If (parent IsNot Nothing) Then

            e.Add(parent)

        End If 

        Return e

    End Function 

End Class
// 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;
        }
    }
}

Inheritance Hierarchy

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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

ItemPolicy Members

Microsoft.Windows.Design.Policies Namespace

PrimarySelectionPolicy

SelectionPolicy

FeatureProvider

FeatureConnectorAttribute

Other Resources

Feature Providers and Feature Connectors

Understanding WPF Designer Extensibility