SelectionPattern.SelectionPatternInformation.CanSelectMultiple 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得值,這個值指定容器是否允許同時選取多個子項目。
public:
property bool CanSelectMultiple { bool get(); };
public bool CanSelectMultiple { get; }
member this.CanSelectMultiple : bool
Public ReadOnly Property CanSelectMultiple As Boolean
屬性值
如果控制項支援多重選取,則為 true
;否則為 false
。
範例
在下列範例中, SelectionPattern 會從 AutomationElement 取得控制項模式,然後用來擷取屬性值。
///--------------------------------------------------------------------
/// <summary>
/// Obtains a SelectionPattern control pattern from an
/// automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A SelectionPattern object.
/// </returns>
///--------------------------------------------------------------------
private SelectionPattern GetSelectionPattern(
AutomationElement targetControl)
{
SelectionPattern selectionPattern = null;
try
{
selectionPattern =
targetControl.GetCurrentPattern(SelectionPattern.Pattern)
as SelectionPattern;
}
// Object doesn't support the SelectionPattern control pattern
catch (InvalidOperationException)
{
return null;
}
return selectionPattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a SelectionPattern control pattern from an
''' automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A SelectionPattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetSelectionPattern( _
ByVal targetControl As AutomationElement) As SelectionPattern
Dim selectionPattern As SelectionPattern = Nothing
Try
selectionPattern = DirectCast( _
targetControl.GetCurrentPattern(selectionPattern.Pattern), _
SelectionPattern)
' Object doesn't support the SelectionPattern control pattern
Catch
Return Nothing
End Try
Return selectionPattern
End Function 'GetSelectionPattern
///--------------------------------------------------------------------
/// <summary>
/// Gets the current property values from target.
/// </summary>
/// <param name="selectionPattern">
/// A SelectionPattern control pattern obtained from
/// an automation element representing the selection control.
/// </param>
/// <param name="automationProperty">
/// The automation property of interest.
/// </param>
///--------------------------------------------------------------------
private bool GetSelectionObjectProperty(
SelectionPattern selectionPattern,
AutomationProperty automationProperty)
{
if (automationProperty.Id ==
SelectionPattern.CanSelectMultipleProperty.Id)
{
return selectionPattern.Current.CanSelectMultiple;
}
if (automationProperty.Id ==
SelectionPattern.IsSelectionRequiredProperty.Id)
{
return selectionPattern.Current.IsSelectionRequired;
}
return false;
}
'''--------------------------------------------------------------------
''' <summary>
''' Gets the current property values from target.
''' </summary>
''' <param name="selectionPattern">
''' A SelectionPattern control pattern obtained from
''' an automation element representing the selection control.
''' </param>
''' <param name="automationProperty">
''' The automation property of interest.
''' </param>
'''--------------------------------------------------------------------
Private Function GetSelectionObjectProperty( _
ByVal selectionPattern As SelectionPattern, _
ByVal automationProperty As AutomationProperty) As Boolean
If automationProperty.Id = _
selectionPattern.CanSelectMultipleProperty.Id Then
Return selectionPattern.Current.CanSelectMultiple
End If
If automationProperty.Id = _
selectionPattern.IsSelectionRequiredProperty.Id Then
Return selectionPattern.Current.IsSelectionRequired
End If
Return False
End Function 'GetSelectionObjectProperty
備註
這個屬性可以是動態的。例如,在少數情況下,控制項可能會允許在初始化時選取多個專案,但後續只允許進行單一選取。