MultipleViewPattern.GetViewName(Int32) 方法

定义

检索特定于控件的视图的名称。

public:
 System::String ^ GetViewName(int viewId);
public string GetViewName (int viewId);
member this.GetViewName : int -> string
Public Function GetViewName (viewId As Integer) As String

参数

viewId
Int32

特定于控件的视图标识符。

返回

一个表示特定于控件的视图名称的本地化字符串。

例外

viewId 不是受支持的视图集合的成员。

示例

在以下示例中,当前视图的控件特定名称是从支持 MultipleViewPattern的控件中检索的。

///--------------------------------------------------------------------
/// <summary>
/// Gets the name of the current view of a target.
/// </summary>
/// <param name="multipleViewControl">
/// The current multiple view control.
/// </param>
/// <returns>
/// The current view name.
/// </returns>
///--------------------------------------------------------------------
private string ViewName(AutomationElement multipleViewControl)
{
    if (multipleViewControl == null)
    {
        throw new ArgumentNullException(
            "AutomationElement parameter must not be null.");
    }

    // Get a MultipleViewPattern from the current control.
    MultipleViewPattern multipleViewPattern =
        GetMultipleViewPattern(multipleViewControl);

    if (multipleViewControl != null)
    {
        try
        {
            int viewID = 
                (int)multipleViewControl.GetCurrentPropertyValue(
                MultipleViewPattern.CurrentViewProperty);
            return multipleViewPattern.GetViewName(viewID);
        }
        catch (ArgumentException)
        {
            // TO DO: error handling
        }
    }
    return null;
}
'/--------------------------------------------------------------------
'/ <summary>
'/ Gets the name of the current view of a target.
'/ </summary>
'/ <param name="multipleViewControl">
'/ The current multiple view control.
'/ </param>
'/ <returns>
'/ The current view name.
'/ </returns>
'/--------------------------------------------------------------------
Private Function ViewName( _
ByVal multipleViewControl As AutomationElement) As String
    If multipleViewControl Is Nothing Then
        Throw New ArgumentNullException( _
        "AutomationElement parameter must not be null.")
    End If

    If Not (multipleViewControl Is Nothing) Then
        Try
            ' Get a MultipleViewPattern from the current control.
            Dim multipleViewPattern As MultipleViewPattern = _
            GetMultipleViewPattern(multipleViewControl)
            Dim viewID As Integer = _
            DirectCast(multipleViewControl.GetCurrentPropertyValue( _
            multipleViewPattern.CurrentViewProperty), Integer)
            Return multipleViewPattern.GetViewName(viewID)
        Catch exc As ArgumentException
            ' TO DO: error handling
        End Try
    End If
    Return Nothing
End Function 'ViewName

注解

可以使用 检索 GetSupportedViews视图标识符。

特定于控件的视图标识符集合在实例之间是相同的。

视图名称适用于文本转语音、盲文和其他辅助应用程序。

适用于