ValuePattern.ValuePatternInformation.Value 属性

定义

获取UI 自动化元素的值。

public:
 property System::String ^ Value { System::String ^ get(); };
public string Value { get; }
member this.Value : string
Public ReadOnly Property Value As String

属性值

String

UI 自动化元素的值作为字符串。 默认值为一个空字符串。

示例

在以下示例中, ValuePattern 从目标控件获取的对象将传递到检索当前 ValuePattern 属性值的函数中。

///--------------------------------------------------------------------
/// <summary>
/// Gets the current property values from target.
/// </summary>
/// <param name="valuePattern">
/// A ValuePattern control pattern obtained from 
/// an automation element representing a target control.
/// </param>
/// <param name="automationProperty">
/// The automation property of interest.
/// </param>
///--------------------------------------------------------------------
private object GetValueProperty(
    ValuePattern valuePattern,
    AutomationProperty automationProperty)
{
    if (valuePattern == null || automationProperty == null)
    {
        throw new ArgumentNullException("Argument cannot be null.");
    }

    if (automationProperty.Id ==
        ValuePattern.ValueProperty.Id)
    {
        return valuePattern.Current.Value;
    }
    return null;
}
'''--------------------------------------------------------------------
''' <summary>
''' Gets the current property values from target.
''' </summary>
''' <param name="valuePattern">
''' A ValuePattern control pattern obtained from 
''' an automation element representing a target control.
''' </param>
''' <param name="automationProperty">
''' The automation property of interest.
''' </param>
'''--------------------------------------------------------------------
Private Function GetValueProperty( _
ByVal valuePattern As ValuePattern, _
ByVal automationProperty As AutomationProperty) As Object
    If (valuePattern Is Nothing Or automationProperty Is Nothing) Then
        Throw New ArgumentNullException("Argument cannot be null.")
    End If

    If automationProperty.Id = valuePattern.ValueProperty.Id Then
        Return valuePattern.Current.Value
    End If
    Return Nothing

End Function 'GetValueProperty

注解

单行编辑控件支持通过 ValuePattern编程方式访问其内容。 但是,多行编辑控件不支持 ValuePattern 控件模式。

若要检索多行编辑控件的文本内容,控件必须支持 TextPattern 控件模式。 但是, TextPattern 不支持设置控件的值。

ValuePattern 不支持检索格式设置信息或子字符串值。 这些 TextPattern 方案必须使用控件模式。

适用于

另请参阅