แก้ไข

แชร์ผ่าน


MultipleViewPattern.GetViewName(Int32) Method

Definition

Retrieves the name of a control-specific view.

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

Parameters

viewId
Int32

The control-specific view identifier.

Returns

A localized string representing the control-specific view name.

Exceptions

viewId is not a member of the supported views collection.

Examples

In the following example, the control-specific name of the current view is retrieved from a control that supports 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

Remarks

View identifiers can be retrieved by using GetSupportedViews.

The control-specific collection of view identifiers is identical across instances.

View names are suitable for use in Text to Speech, Braille, and other accessible applications.

Applies to