FrameworkContentElement.FindName(String) 方法

定義

尋找具有所提供之識別項名稱的項目。Finds an element that has the provided identifier name.

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

參數

name
String

要搜尋的項目名稱。Name of the element to search for.

傳回

要求的項目。The requested element. 如果找不到相符的項目,則可能為 nullMay be null if no matching element was found.

範例

下列範例會在頁面上參考的 FlowDocument 中,于名稱所找到的元素上設定屬性。The following example sets a property on an element found by name within a referenced FlowDocument on a page.

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

備註

如果這個專案有子專案,則會以遞迴方式搜尋所要求之已命名專案的子項目。If this element has child elements, these child elements are all searched recursively for the requested named element.

適用於