ExpandCollapsePattern.ExpandCollapsePatternInformation.ExpandCollapseState Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene l'oggetto ExpandCollapseState di AutomationElement.
public:
property System::Windows::Automation::ExpandCollapseState ExpandCollapseState { System::Windows::Automation::ExpandCollapseState get(); };
public System.Windows.Automation.ExpandCollapseState ExpandCollapseState { get; }
member this.ExpandCollapseState : System.Windows.Automation.ExpandCollapseState
Public ReadOnly Property ExpandCollapseState As ExpandCollapseState
Valore della proprietà
Oggetto ExpandCollapseState dell'oggetto AutomationElement.
Esempio
Nell'esempio seguente un oggetto AutomationElement che rappresenta una voce di menu viene passato a una funzione che tenta di espandere o comprimere la voce di menu in base alla relativa corrente ExpandCollapseState.
///--------------------------------------------------------------------
/// <summary>
/// Obtains an ExpandCollapsePattern control pattern from an
/// automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A ExpandCollapsePattern object.
/// </returns>
///--------------------------------------------------------------------
private ExpandCollapsePattern GetExpandCollapsePattern(
AutomationElement targetControl)
{
ExpandCollapsePattern expandCollapsePattern = null;
try
{
expandCollapsePattern =
targetControl.GetCurrentPattern(
ExpandCollapsePattern.Pattern)
as ExpandCollapsePattern;
}
// Object doesn't support the ExpandCollapsePattern control pattern.
catch (InvalidOperationException)
{
return null;
}
return expandCollapsePattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains an ExpandCollapsePattern control pattern from an
''' automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A ExpandCollapsePattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetExpandCollapsePattern( _
ByVal targetControl As AutomationElement) As ExpandCollapsePattern
Dim expandCollapsePattern As ExpandCollapsePattern = Nothing
Try
expandCollapsePattern = DirectCast( _
targetControl.GetCurrentPattern(expandCollapsePattern.Pattern), _
ExpandCollapsePattern)
Catch exc As InvalidOperationException
' Object doesn't support the ExpandCollapsePattern control pattern.
Return Nothing
End Try
Return expandCollapsePattern
End Function 'GetExpandCollapsePattern
///--------------------------------------------------------------------
/// <summary>
/// Programmatically expand or collapse a menu item.
/// </summary>
/// <param name="menuItem">
/// The target menu item.
/// </param>
///--------------------------------------------------------------------
private void ExpandCollapseMenuItem(
AutomationElement menuItem)
{
if (menuItem == null)
{
throw new ArgumentNullException(
"AutomationElement argument cannot be null.");
}
ExpandCollapsePattern expandCollapsePattern =
GetExpandCollapsePattern(menuItem);
if (expandCollapsePattern == null)
{
return;
}
if (expandCollapsePattern.Current.ExpandCollapseState ==
ExpandCollapseState.LeafNode)
{
return;
}
try
{
if (expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Expanded)
{
// Collapse the menu item.
expandCollapsePattern.Collapse();
}
else if (expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.Collapsed ||
expandCollapsePattern.Current.ExpandCollapseState == ExpandCollapseState.PartiallyExpanded)
{
// Expand the menu item.
expandCollapsePattern.Expand();
}
}
// Control is not enabled
catch (ElementNotEnabledException)
{
// TO DO: error handling.
}
// Control is unable to perform operation.
catch (InvalidOperationException)
{
// TO DO: error handling.
}
}
'''--------------------------------------------------------------------
''' <summary>
''' Programmatically expand or collapse a menu item.
''' </summary>
''' <param name="menuItem">
''' The target menu item.
''' </param>
'''--------------------------------------------------------------------
Private Sub ExpandCollapseMenuItem(ByVal menuItem As AutomationElement)
If menuItem Is Nothing Then
Throw New ArgumentNullException( _
"AutomationElement argument cannot be null.")
End If
Dim expandCollapsePattern As ExpandCollapsePattern = _
GetExpandCollapsePattern(menuItem)
If expandCollapsePattern Is Nothing Then
Return
End If
If expandCollapsePattern.Current.ExpandCollapseState = _
ExpandCollapseState.LeafNode Then
Return
End If
Try
If expandCollapsePattern.Current.ExpandCollapseState = _
ExpandCollapseState.Expanded Then
' Collapse the menu item.
expandCollapsePattern.Collapse()
ElseIf expandCollapsePattern.Current.ExpandCollapseState = _
ExpandCollapseState.Collapsed OrElse _
expandCollapsePattern.Current.ExpandCollapseState = _
ExpandCollapseState.PartiallyExpanded Then
' Expand the menu item.
expandCollapsePattern.Expand()
End If
Catch exc As ElementNotEnabledException
' Control is not enabled
' TO DO: error handling.
Catch exc As InvalidOperationException
' Control is unable to perform operation
' TO DO: error handling.
End Try
End Sub
Commenti
ExpandCollapseState si riferisce solo alla visibilità di oggetti figlio diretti, non alla visibilità di tutti gli oggetti discendenti.
Il valore predefinito è Expanded.