Export (0) Print
Expand All

RangeValuePattern.RangeValuePatternInformation.IsReadOnly Property

Gets a value that specifies whether the value of a UI Automation element is read-only.

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

public bool IsReadOnly { get; }

Property Value

Type: System.Boolean
true if the value is read-only; false if it can be modified. The default is true.

A control should have its IsEnabledProperty set to true and its IsReadOnlyProperty set to false prior to the creation of a RangeValuePattern object.

In the following example, an AutomationElement that supports the RangeValuePattern control pattern has its value incremented or decremented by the control-specific LargeChange value.

SetRangeValue(targetControl[0], rangeValuePattern.Current.LargeChange, -1);


...


///-------------------------------------------------------------------- 
/// <summary> 
/// Sets the range value of the control of interest. 
/// </summary> 
/// <param name="targetControl">
/// The automation element of interest. 
/// </param> 
/// <param name="rangeValue">
/// The value (either relative or absolute) to set the control to. 
/// </param> 
/// <param name="rangeDirection">
/// The value used to specify the direction of adjustment. 
/// </param> 
///-------------------------------------------------------------------- 
private void SetRangeValue(
    AutomationElement targetControl,
    double rangeValue,
    double rangeDirection)
{
    if (targetControl == null || rangeValue == 0 || rangeDirection == 0)
    {
        throw new ArgumentException("Argument cannot be null or zero.");
    }

    RangeValuePattern rangeValuePattern =
        GetRangeValuePattern(targetControl);

    if (rangeValuePattern.Current.IsReadOnly)
    {
        throw new InvalidOperationException("Control is read-only.");
    }

    rangeValue = rangeValue * Math.Sign(rangeDirection);

    try
    {
        if ((rangeValue <= rangeValuePattern.Current.Maximum) ||
            (rangeValue >= rangeValuePattern.Current.Minimum))
        {
            rangeValuePattern.SetValue(rangeValue);
        }
    }
    catch (ArgumentOutOfRangeException)
    {
        // TO DO: Error handling.
    }
    catch (ArgumentException)
    {
        // TO DO: Error handling.
    }
}


...


///-------------------------------------------------------------------- 
/// <summary> 
/// Obtains a RangeValuePattern control pattern from an  
/// automation element. 
/// </summary> 
/// <param name="targetControl">
/// The automation element of interest. 
/// </param> 
/// <returns> 
/// A RangeValuePattern object. 
/// </returns> 
///-------------------------------------------------------------------- 
private RangeValuePattern GetRangeValuePattern(
    AutomationElement targetControl)
{
    RangeValuePattern rangeValuePattern = null;

    try
    {
        rangeValuePattern =
            targetControl.GetCurrentPattern(
            RangeValuePattern.Pattern)
            as RangeValuePattern;
    }
    // Object doesn't support the  
    // RangeValuePattern control pattern 
    catch (InvalidOperationException)
    {
        return null;
    }

    return rangeValuePattern;
}

.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