ItemPolicy.GetSurrogateItems Method

Returns an optional set of surrogate items for this item.

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

Syntax

'Declaration
Public Overridable Function GetSurrogateItems ( _
    item As ModelItem _
) As IEnumerable(Of ModelItem)
public virtual IEnumerable<ModelItem> GetSurrogateItems(
    ModelItem item
)
public:
virtual IEnumerable<ModelItem^>^ GetSurrogateItems(
    ModelItem^ item
)
abstract GetSurrogateItems : 
        item:ModelItem -> IEnumerable<ModelItem> 
override GetSurrogateItems : 
        item:ModelItem -> IEnumerable<ModelItem> 
public function GetSurrogateItems(
    item : ModelItem
) : IEnumerable<ModelItem>

Parameters

Return Value

Type: System.Collections.Generic.IEnumerable<ModelItem>
An enumeration of surrogate items to check. The default returns an empty enumeration.

Remarks

Surrogate items provide additional features for the specified item. Surrogate items are not part of the items that are exposed to consumers of the policy. Return surrogate items if you need a parent object to offer features for a child. To return a set of surrogate items, override the IsSurrogate property so that it returns true.

Note

Do not return nulla null reference (Nothing in Visual Basic) from your GetSurrogateItems implementation.

Examples

The following code example shows how to create a custom surrogate policy by implementing the IsSurrogate property and the GetSurrogateItems method. 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;
        }
    }
}

.NET Framework Security

See Also

Reference

ItemPolicy Class

Microsoft.Windows.Design.Policies Namespace

PrimarySelectionPolicy

SelectionPolicy

FeatureProvider

FeatureConnectorAttribute

Other Resources

Feature Providers and Feature Connectors

Understanding WPF Designer Extensibility