FrameworkContentElement.FindName(String) Méthode

Définition

Recherche un élément qui a le nom de l’identificateur fourni.

public:
 System::Object ^ FindName(System::String ^ name);
public object FindName (string name);
member this.FindName : string -> obj
Public Function FindName (name As String) As Object

Paramètres

name
String

Nom de l'élément à rechercher.

Retours

Object

Élément demandé. Peut avoir la valeur null si aucun élément correspondant n'est trouvé.

Exemples

L’exemple suivant définit une propriété sur un élément trouvé par un nom dans une page référencée FlowDocument .

void HighlightParagraph(string paraName)
{
    try
    {
        Paragraph wantedNode = (Paragraph)myflowdocument.FindName(paraName);
        if (wantedNode != null)
        {
            wantedNode.Background = Brushes.LightYellow;
        }
    }
    catch { }//handle paragraph not found in UI }
}
Private Sub HighlightParagraph(ByVal paraName As String)
    Try
        Dim wantedNode As Paragraph = CType(myflowdocument.FindName(paraName), Paragraph)
        If wantedNode IsNot Nothing Then
            wantedNode.Background = Brushes.LightYellow
        End If
    Catch 'handle paragraph not found in UI }
    End Try
End Sub

Remarques

Si cet élément a des éléments enfants, ces éléments enfants sont tous recherchés de manière récursive pour l’élément nommé demandé.

S’applique à