SelectionPolicy Class

A policy that makes all items in the selection available.

Inheritance Hierarchy

System.Object
  Microsoft.Windows.Design.Policies.ItemPolicy
    Microsoft.Windows.Design.Policies.SelectionPolicy
      Microsoft.Windows.Design.Policies.PrimarySelectionPolicy
      Microsoft.Windows.Design.Policies.SecondarySelectionPolicy
      Microsoft.Windows.Design.Policies.SelectionParentPolicy

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

Syntax

'Declaration
<RequiresContextItemAttribute(GetType(Selection))> _
<RequiresContextItemAttribute(GetType(Tool))> _
Public Class SelectionPolicy _
    Inherits ItemPolicy
[RequiresContextItemAttribute(typeof(Selection))]
[RequiresContextItemAttribute(typeof(Tool))]
public class SelectionPolicy : ItemPolicy
[RequiresContextItemAttribute(typeof(Selection))]
[RequiresContextItemAttribute(typeof(Tool))]
public ref class SelectionPolicy : public ItemPolicy
[<RequiresContextItemAttribute(typeof(Selection))>]
[<RequiresContextItemAttribute(typeof(Tool))>]
type SelectionPolicy =  
    class
        inherit ItemPolicy
    end
public class SelectionPolicy extends ItemPolicy

The SelectionPolicy type exposes the following members.

Constructors

  Name Description
Public method SelectionPolicy Initializes a new instance of the SelectionPolicy class.

Top

Properties

  Name Description
Protected property Context Gets the editing context for the designer. (Inherited from ItemPolicy.)
Public property IsSurrogate Gets a value indicating whether the policy is a surrogate policy. (Inherited from ItemPolicy.)
Public property PolicyItems Gets an enumeration of items that are affected by this policy. (Overrides ItemPolicy.PolicyItems.)

Top

Methods

  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.)
Protected method GetPolicyItems Returns the policy items from the specified selection.
Public method GetSurrogateItems Returns an optional set of surrogate items for this item. (Inherited from ItemPolicy.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method IsInPolicy Gets a value indicating whether the specified item is to be included in the policy.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnActivated Called when this policy is activated. (Overrides ItemPolicy.OnActivated().)
Protected method OnDeactivated Called when this policy is deactivated. (Overrides ItemPolicy.OnDeactivated().)
Protected method OnPolicyItemsChanged Raises the PolicyItemsChanged event. (Inherited from ItemPolicy.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Events

  Name Description
Public event PolicyItemsChanged Occurs when the policy changes. (Inherited from ItemPolicy.)

Top

Remarks

Derive from this policy and override the IsInPolicy and GetPolicyItems methods to filter the selection as necessary.

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;
        }
    }
}

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

Microsoft.Windows.Design.Policies Namespace

ItemPolicy

FeatureProvider

FeatureConnector<TFeatureProviderType>

Other Resources

Feature Providers and Feature Connectors

Understanding WPF Designer Extensibility