Share via


PrimarySelectionPolicy Class

A policy that specifies the primarily selected element.

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

Syntax

'Declaration
Public Class PrimarySelectionPolicy _
    Inherits SelectionPolicy
'Usage
Dim instance As PrimarySelectionPolicy
public class PrimarySelectionPolicy : SelectionPolicy
public ref class PrimarySelectionPolicy : public SelectionPolicy
public class PrimarySelectionPolicy extends SelectionPolicy

Remarks

The PrimarySelectionPolicy class is an ItemPolicy that is enabled for the primarily selected element when SelectionTool is the active tool.

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
      Microsoft.Windows.Design.Policies.PrimarySelectionPolicy

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

PrimarySelectionPolicy Members

Microsoft.Windows.Design.Policies Namespace

ItemPolicy

SelectionPolicy

FeatureProvider

FeatureConnectorAttribute

Other Resources

Feature Providers and Feature Connectors

Understanding WPF Designer Extensibility