ISelectionItemProvider.AddToSelection 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将当前元素添加到所选项的集合。
public:
void AddToSelection();
public void AddToSelection ();
abstract member AddToSelection : unit -> unit
Public Sub AddToSelection ()
示例
下面的示例代码将项添加到选定项的集合中。
/// <summary>
/// Adds an item to the selection for list boxes that
/// support multiple selection.
/// </summary>
/// <remarks>
/// In a single-selection list box, AddToSelection() is
/// equivalent to Select().
/// selectedItems is the collection of selected ListItems.
/// </remarks>
public void AddToSelection()
{
// Return if the item is already selected.
if (((ISelectionItemProvider)this).IsSelected)
return;
selectedItems.Add(this);
// TODO: Update UI.
}
''' <summary>
''' Adds an item to the selection for list boxes that
''' support multiple selection.
''' </summary>
''' <remarks>
''' In a single-selection list box, AddToSelection() is
''' equivalent to Select().
''' selectedItems is the collection of selected ListItems.
''' </remarks>
Public Sub AddToSelection() Implements ISelectionItemProvider.AddToSelection
' Return if the item is already selected.
If (CType(Me, ISelectionItemProvider)).IsSelected Then
Return
End If
selectedItems.Add(Me)
' TODO: Update UI.
End Sub
/// <summary>
/// Specifies whether the item is selected.
/// </summary>
/// <remarks>
/// selectedItems is the collection of selected ListItems.
/// </remarks>
public bool IsSelected
{
get
{
return selectedItems.Contains(this);
}
}
''' <summary>
''' Specifies whether the item is selected.
''' </summary>
''' <remarks>
''' selectedItems is the collection of selected ListItems.
''' </remarks>
Public ReadOnly Property IsSelected() As Boolean Implements ISelectionItemProvider.IsSelected
Get
Return selectedItems.Contains(Me)
End Get
End Property
注解
如果调用 AddToSelection 的结果是选择了单个项,则为该元素发送 ElementSelectedEvent ;否则根据需要发送 ElementAddedToSelectionEvent 或 ElementRemovedFromSelectionEvent 。
注意
此规则不取决于容器是允许单选还是多选,也不取决于用于更改所选内容的方法。 只有结果才重要。