SelectionPattern.SelectionPatternInformation.IsSelectionRequired 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值指定容器是否要求至少选择一个子项。
public:
property bool IsSelectionRequired { bool get(); };
public bool IsSelectionRequired { get; }
member this.IsSelectionRequired : bool
Public ReadOnly Property IsSelectionRequired 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
注解
此属性可以是动态的。 例如,控件的初始状态默认可能未选择任何项,指示 IsSelectionRequired 是 false
。 但是,选择某一项后,该控件必须始终具有至少一个选定的项。