Export (0) Print
Expand All

SelectionPattern.SelectionPatternInformation.IsSelectionRequired Property

Gets a value that specifies whether the container requires at least one child item to be selected.

Namespace:  System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public bool IsSelectionRequired { get; }

Property Value

Type: System.Boolean
true if the control requires at least one item to be selected; otherwise false.

This property can be dynamic. For example, the initial state of a control might not have any items selected by default, indicating that IsSelectionRequired is false. However, after an item is selected, the control must always have at least one item selected.

In the following example, a SelectionPattern control pattern is obtained from an AutomationElement and subsequently used to retrieve property values.

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft