AutomationElement.ClassNameProperty 欄位

定義

識別 ClassName 屬性。

public: static initonly System::Windows::Automation::AutomationProperty ^ ClassNameProperty;
public static readonly System.Windows.Automation.AutomationProperty ClassNameProperty;
 staticval mutable ClassNameProperty : System.Windows.Automation.AutomationProperty
Public Shared ReadOnly ClassNameProperty As AutomationProperty 

欄位值

範例

下列範例會擷取 屬性的目前值。 如果專案未提供預設值,則會傳回預設值。

string className =
    autoElement.GetCurrentPropertyValue(AutomationElement.ClassNameProperty) as string;
Dim className As Object = autoElement.GetCurrentPropertyValue(AutomationElement.ClassNameProperty)

下列範例會擷取屬性的目前值,但指定如果專案本身未提供屬性的值, NotSupported 則會傳回 而不是預設值。

string classNameString;
object classNameNoDefault =
    autoElement.GetCurrentPropertyValue(AutomationElement.ClassNameProperty, true);
if (classNameNoDefault == AutomationElement.NotSupported)
{
    // TODO Handle the case where you do not wish to proceed using the default value.
}
else
{
    classNameString = classNameNoDefault as string;
}
Dim classNameString As String
Dim classNameNoDefault As Object = autoElement.GetCurrentPropertyValue(AutomationElement.ClassNameProperty, True)
If classNameNoDefault Is AutomationElement.NotSupported Then
    ' TODO Handle the case where you do not wish to proceed using the default value.
Else
    classNameString = CStr(classNameNoDefault)
End If

備註

使用者介面自動化用戶端應用程式會使用此識別碼。 使用者介面自動化提供者應該使用 中的 AutomationElementIdentifiers 對等識別碼。

您也可以從 CurrentCached 屬性擷取這個屬性。

類別名稱取決於使用者介面自動化提供者的實作,因此無法計算為標準格式。 不過,如果您知道類別名稱,您可以使用它來驗證您的應用程式是否使用預期的 UI 自動化元素。

屬性的傳回值的類型為 String 。 預設值為空字串。

適用於

另請參閱