Поделиться через


SelectionPolicy - класс

Обновлен: Ноябрь 2007

Политика, обеспечивающая доступность всех элементов в выделении.

Пространство имен:  Microsoft.Windows.Design.Policies
Сборка:  Microsoft.Windows.Design.Extensibility (в Microsoft.Windows.Design.Extensibility.dll)

Синтаксис

'Декларация
<RequiresContextItemAttribute(GetType(Selection))> _
<RequiresContextItemAttribute(GetType(Tool))> _
Public Class SelectionPolicy _
    Inherits ItemPolicy
'Применение
Dim instance As SelectionPolicy
[RequiresContextItemAttribute(typeof(Selection))]
[RequiresContextItemAttribute(typeof(Tool))]
public class SelectionPolicy : ItemPolicy
[RequiresContextItemAttribute(typeof(Selection))]
[RequiresContextItemAttribute(typeof(Tool))]
public ref class SelectionPolicy : public ItemPolicy
public class SelectionPolicy extends ItemPolicy

Заметки

Для фильтрации выделения выполните наследование от этой политики и переопределите методы IsInPolicy и GetPolicyItems.

Примеры

В следующем примере кода показано, как реализовать пользовательскую политику замещения для первичного объекта выделения. Полный пример кода см. в разделе Практическое руководство. Создание политики замещения.

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

Иерархия наследования

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

Потокобезопасность

Любые открытые члены этого типа, объявленные как static (Shared в Visual Basic), являются потокобезопасными. Потокобезопасность членов экземпляров не гарантируется.

См. также

Ссылки

SelectionPolicy - члены

Microsoft.Windows.Design.Policies - пространство имен

ItemPolicy

FeatureProvider

FeatureConnector<TFeatureProviderType>

Другие ресурсы

Поставщики функций и соединительные элементы

Общее представление о расширяемости конструктора WPF